按CTRL+N新建一个FLA文件,然后在时间轴上插入三个空白关键桢(这个大家都会吧),然后将图层命名为AS,在第一桢中插入如下代码:
A = 100;//定义雪花个数
B = 2;//初始值
_root.createEmptyMovieClip("bg", 0);/*创建空白影片剪辑创建一个黑的与场景大小一样的影片作为背景*/
with (_root.bg) {
this.beginFill(0x000000, 100);
this.moveTo(0, 0);
this.lineTo(0, 0);
this.lineTo(0, Stage.height);
this.lineTo(Stage.width, Stage.height);
this.lineTo(Stage.width, 0);
this.lineTo(0, 0);
this.endFill();
}//用画线来画背景
_root.createEmptyMovieClip("xue", 1);/*利用画线创建雪花,其实就是一个白色的园*/
with (_root.xue) {
beginFill(0xffffff, 100);
moveTo(5, 0);
curveTo(0, 0, 0, 5);
curveTo(0, 10, 5, 10);
tcurveTo(10, 10, 15, 10);
curveTo(15, 0, 5, 0);
endFill();
}
_root.xue._visible = false;//隐藏影片剪辑
for (var i = B; i
duplicateMovieClip("_root.xue", "xue"+i, i);
_root["xue"+i]._x = random(Stage.width);
_root["xue"+i]._y = random(Stage.height);
_root["xue"+i]._xscale = _root["xue"+i]._yscale=50+i*Math.abs(Math.sin(Math.random(50)+i))/4;
_root["xue"+i]._alpha = random(70)+30;
_root["su"+i] = Math.cos(Math.random()*A/2-A);
}//这个是主场景中第一桢的脚本
然后在第二桢上加上如下脚本:
function go(k) {自定义函数,让雪花动起来
_root["xue"+k]._x += _root["su"+k]*2;//定义雪花的X轴运动方式
_root["xue"+k]._y += 3;//定义雪花Y轴的运动方式
if (_root["xue"+k]._x>Stage.width) {/*定义界限,当雪花超出场景时返回初始状态,这样可以使雪花不断出现*/
_root["xue"+k]._x = 0;
} else if (_root["xue"+k]._x<0) {
_root["xue"+k]._x = Stage.width;
}
if (this["xue"+k]._y>Stage.height) {
this["xue"+k]._y = 0;
} else if (_root["xue"+k]._y<0) {
_root["xue"+k]._x = Stage.height;
}
}
for (var k =B; k
go(k);
}//复重复执行自定义函数,让雪花漂起来
这是第三桢的脚本:
gotoAndPlay(2);