flash制作旋转小星星动画(代码实现)
点评:本文主要是为大家介绍如何使用flash代码实现flash动画效果的小星星。有兴趣的朋友可以看看。具体过程如下:
1,一个新的FLA文件,400宽400,帧频默认背景颜色为黑色,保存。
2,选择多边形工具,设置为5面,星形。在舞台上绘制任意颜色和大小的星星。
3、在选定的状态下,右键转换为电影剪辑,全部对齐,命名为星,删除舞台上的星星。
4、按Ctrl + L组合键,打开库面板,右键单击明星影片剪辑,选择属性;;打开构件属性面板,检查脚本选项,使影片剪辑结合星级。图:
5、下列代码为星级的编写和建立新的Actionscript文件。
输入以下代码:
包{
进口flash.display.movieclip;
进口flash.geom.colortransform;
导入Flash事件;
公共类明星扩展MovieClip {
机车的starcolor:单元;
机车的starrotation:数;
公共函数星(){
计算一个随机颜色
this.starcolor = Math.random()* 0xffffff;
获得与明星的colortransform实例 /。
VaR讯彩:colortransform = this.transform.colortransform;
设置的colortransform / /对象的颜色。
colorinfo.color = this.starcolor;
星星的颜色
this.transform.colortransform =讯彩;
为星星分配一个随机alpha值
this.alpha = Math.random();
分配随机旋转速度
this.starrotation = Math.random()×10-5;
分配随机数
this.scalex = Math.random();
this.scaley = this.scalex;
/ /添加enter_frame我们做动画
AddEventListener(event.enter_frame,rotatestar);
}
这个函数负责星的旋转。
私有函数rotatestar(E:事件):无效{
this.rotation = this.starrotation;
}
}
}
6、保存在目录为FLA相同,并且名称是star.as.note:这一步是非常重要的,必须保持在同一目录下的FLA文件,如果是保存在其他目录的路径指定。初学者往往不能在测试中发现的错误类提示和问题都在这里。
7、回到佛罗里达,第一帧输入代码在第一层:
对于(var i = 0;i < 100;i + +){
var星:星=新星();
明星。x = stage.stagewidth * Math.random();
明星。Y = stage.stageheight * Math.random();
addChild(星);
}
8。好吧。所有的工作都做完了。测试你的胶卷。