Flash制作旋转小星星动画?
具体制作过程如下:
1、新建一个fla文件,宽400高400,帧频默认,背景颜色黑色,保存。
2、选择多边形工具,设置为5边,星形。在舞台上画一个任意颜色、大小的星。
3、在选取状态下,右键转换为影片剪辑,全对齐,命名为Star,删除舞台上的星。
4、按CtrlL组合键,打开库面板,右键单击Star影片剪辑,选择ldquo;属性rdquo;打开元件属性面板,勾选ActionScript选项,这样就使影片剪辑与Star类进行了绑定。如图:
5、下面开始编写Star类的代码,新建一个ActionScript文件。
输入下面的代码:
package{
importFlash。display。MovieClip;
importflash。geom。ColorTransform;
importflash。events。;
publicclassStarextendsMovieClip{
privatevarstarColor:uint;
privatevarstarRotation:Number;
publicfunctionStar(){
Calculatearandomcolor
this。starColorMath。random()0xffffff;
GetAccesstotheColorTransforminstanceassociatedwithstar。
varcolorInfo:ColorTransformthis。transform。colorTransform;
SetthecoloroftheColorTransformobject。
colorInfo。colorthis。starColor;
applythecolortothestar
this。transform。colorTransformcolorInfo;
Assignarandomalphaforthestar
this。alphaMath。random();
Assignarandomrotationspeed
this。starRotationMath。random()105;
Assignarandomscale
this。scaleXMath。random();
this。scaleYthis。scaleX;
AddENTERFRAMEwherewedotheanimation
addEventListener(Event。ENTERFRAME,rotateStar);
}
Thisfunctionisresponsiblefortherotationofthestar
privatefunctionrotateStar(e:Event):void{
this。rotationthis。starRotation;
}
}
}
6、保存在fla同一目录下,保存名为Star。as。注意:这一步非常重要,一定要同fla主文件保存在相同的目录下,如果保存在其它的目录下,要指明路径。初学者在测试时往往出现找不到类的错误提示,问题都在这里。
7、返回到fla,在第1层的第一帧输入代码:
for(vari0;ilt;100;i){
varstar:StarnewStar();
star。xstage。stageWidthMath。random();
star。ystage。stageHeightMath。random();
addChild(star);
}
8、好了,所有的工作都已经完成,测试你的影片。