用户名 密    码

Flash动画教程:创建好看的遮罩动画效果(5)

来源:互联网 作者:未知 发布时间:2011-03-26 09:12:47 网友评论 0


10、把图层2改为as,输入代码:



//We need these classes for the animation

import fl.transitions.Tween;

import fl.transitions.easing.*;



//These are the mask rectangle’s width and height

var boxWidth:Number = 40;

var boxHeight:Number = 40;



//We want nine rows and 14 columns to make the animation look nice

var rows:Number = 9;

var columns:Number = 14;



//We will add the rectangle’s into an array (we need this array in the animation)

var rectangles:Array = new Array();



//We add the tweens into an array so they don’t get carbage collected

var tweens:Array = new Array();



//This container will hold all the mask rectangles

var container:Sprite = new Sprite();



//Add the container onto the stage

addChild(container);



//Set the container to be the image’s mask

cityMC.mask = container;



//Loop through the rows

for (var i=0; i < rows; i++) {



        //Loop through the columns

        for (var j=0; j < columns; j++) {



                //Create a new mask rectangle

                var maskRectangle:MaskRectangle = new MaskRectangle();



                //Position the mask rectangle

                maskRectangle.x = j * boxWidth;

                maskRectangle.y = i * boxWidth;



                //Set the scaleX to be 0, so the rectangle will not be visible

                maskRectangle.scaleX = 0;



                //Add the rectangle onto the container

                container.addChild(maskRectangle);



                //Add the mask rectangle to the rectangles array

                rectangles.push(maskRectangle);

        }

}



//Create and start a timer.

//This timer is called as many times as there are rectangles on the stage.

var timer = new Timer(35,rectangles.length);

timer.addEventListener(TimerEvent.TIMER, animateMask);

timer.start();



//This function is called every 0.035 seconds

function animateMask(e:Event):void {



        //Save the rectangle to a local variable

        var rectangle = rectangles[timer.currentCount - 1];



        //Tween the scaleX of the rectangle

        var scaleTween:Tween = new Tween(rectangle,"scaleX",Regular.easeOut,0,1,1,true);

        tweens.push(scaleTween);



}

11、完工,测试影片。

搜索栏目