图5
第1帧中的代码如下:
// 变量flakes用来控制雪花的数量,即密度
// _visible属性隐藏母本
n = 1;
flakes = 100;
雪花._visible = 0;
第2帧中的代码如下:
i = 1;
while (i<=flakes) {
//控制雪花飘落速度
this["雪花" add i]._y += Math.random()*2+2;
i++;
}
if (n == flakes) {
n = 1;
} else {
// Math.random()方法取0到1之间的随机数
ssize = Math.random()*50+30;
// 复制雪花
duplicateMovieClip("雪花", "雪花" add n, n);
// 控制雪花飘落范围
this["雪花" add n]._x = Math.random()*500;
// 雪花随机变换大小
this["雪花" add n]._xscale = ssize;
this["雪花" add n]._yscale = ssize;
n++;
}
第3帧中的代码如下:
// 返回到第2帧播放
gotoAndPlay(2);
效果到这里就完成了。代码中的this对象的作用是引用影片剪辑实例。