flash9飘雪效果
1、在flash中制作一个影片剪辑雪花
2、使用如下类:
package {
import flash.display.*;
import flash.events.*;
public class Snow extends MovieClip {
var speedx=0;
var speedy=0;
public function Snow() {
speedx=.8 * Math.random() - 0.4;
speedy=5 * Math.random();
this.addEventListener(Event.ENTER_FRAME,Mot);
}
function Mot(e:Event) {
this.x+= speedx;
this.y+= speedy;
if (this.y >400) {
init();
}
}
function init() {
this.y=0;
this.x=Math.random() * 550;
}
}
}
在flash中右键选中库中的雪花影片剪辑,在类中输入Snow
在flash中加入如下代码:
function DisplaySnows() {
for (var i:int = 0; i < 200; i++) {
var newSnow:Snow = new Snow();
this.addChild(newSnow);
newSnow.x = Math.random()*500;
newSnow.y =-Math.random()*300;
newSnow.alpha = .3+Math.random()*.7;
var scale:Number = .3+Math.random();
newSnow.scaleX = newSnow.scaleY = scale;
}
}
DisplaySnows();