Create Snowfall Easily in Flash CS4
This code show how to create snowfall in flash cs4
u can also use the code for cs3
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.filters.BlurFilter;
import druva.NumberUtil;
import flash.utils.Timer;
import flash.events.*;
public class snowfall extends MovieClip {
private var t:Timer;
public function snowfall():void {
t=new Timer(80);
t.addEventListener(TimerEvent.TIMER, createParticle);
t.start();
}
private function createParticle(e:TimerEvent) {
var mc_particle:MovieClip =new MovieClip();
mc_particle.graphics.beginFill(0xFFFFFF,1);
mc_particle.graphics.drawCircle(0, 0, NumberUtil.getRand(3,5));
mc_particle.graphics.endFill();
mc_particle.x=NumberUtil.getRand(-60,600);
mc_particle.wind = (NumberUtil.getRand(0,1) == 1) ? 'left' : 'right';
mc_particle.filters=[new BlurFilter(10,10,2)];
mc_particle.addEventListener(Event.ENTER_FRAME, moveParticle);
addChild(mc_particle);
}
function moveParticle(e:Event):void {
var targ:MovieClip=MovieClip(e.target);
if (targ.y>400) {
targ.removeEventListener(Event.ENTER_FRAME,moveParticle);
removeChild(targ);
return;
}
targ.y += 1;
if (targ.wind=='left') {
targ.x += 0.4;
} else if (targ.wind== 'right') {
targ.x -= 0.4;
}
}
}
}