思路:
当主场景加载时,有一定数量的雪花随机地分布在画面上,每帧播放后,这些雪花又会在x轴和y轴方向进行随机的位移,从而在整体上产生下雪的效果.
步骤:
1.打开flash MX 2004,新建文档,文档大小550*400像素,帧频设为25FPS.
2.用线条工具在舞台上画出一朵雪花,将该雪花选中,按F8将其转换为电影剪辑,将主场景雪花电影剪辑删除.
3.按ctrl L打开库,在库中选中雪花电影剪辑,按右键后,在弹出的菜单中选"链接",在接下来弹出的"链接属性"窗口中,将"标识符"设为snow,并在"为动作脚本导出"和"在第一帧导出"前打上勾.
4.回主场景,选中图层1的第1帧,按F9键打开动作脚本编辑窗口,输入以下代码:
this.onLoad = function (){
n = 60;
var i = 1;
while (n >= i){
this.attachMovie("snow", "snow" i, i);
var a = Math.round(60 * Math.random() 41);
var b = Math.round(50 * Math.random() 51);
with (this["snow" i]){
_x = 550 * Math.random();
_y = 400 * Math.random();
_xscale = a;
_yscale = a;
_alpha = b;
_rotation =a;
this["snow" i].x = Math.cos(Math.PI * Math.random());//雪花沿x轴每帧播放后的位移增量
this["snow" i].y = 2 2*Math.random();//雪花沿y轴每帧播放后的位移增量
}
i ;
}
}
this.onLoad();
this.onEnterFrame = function(){
var a = 1;
while (n>= a){
with (this["snow" a]){
_x = x;
_y = y;
_rotation = y;
if (_y > 400){
_y =0;
}else if (_x>550){
_x=0;
}else if(_x<0){
_x=550;
}
}
a ;
}
}
n = 60;
var i = 1;
while (n >= i){
this.attachMovie("snow", "snow" i, i);
var a = Math.round(60 * Math.random() 41);
var b = Math.round(50 * Math.random() 51);
with (this["snow" i]){
_x = 550 * Math.random();
_y = 400 * Math.random();
_xscale = a;
_yscale = a;
_alpha = b;
_rotation =a;
this["snow" i].x = Math.cos(Math.PI * Math.random());//雪花沿x轴每帧播放后的位移增量
this["snow" i].y = 2 2*Math.random();//雪花沿y轴每帧播放后的位移增量
}
i ;
}
}
this.onLoad();
this.onEnterFrame = function(){
var a = 1;
while (n>= a){
with (this["snow" a]){
_x = x;
_y = y;
_rotation = y;
if (_y > 400){
_y =0;
}else if (_x>550){
_x=0;
}else if(_x<0){
_x=550;
}
}
a ;
}
}
5.按ctrl enter测试影片
明:这里用到了while循环,当然也可用for循环。
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!




