Flash CS3 - Snowfall
Download flashSnowCS3.zip (7 KB)
// Developed by Anil kumar N D
// anilkumarnd@gmail.com
// http://flash-workshop.blogspot.com/
// ActionScript 3.0package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.filters.BlurFilter;public class flashSnow extends MovieClip {
public function flashSnow():void {
stage.frameRate=30;
stage.addEventListener(Event.ENTER_FRAME,createSnow);
}
function createSnow(IN_Event:Event):void {
if (randomInRange(1,3)==1) {
var mc_particle:MovieClip=createCircle(randomInRange(3,10));
mc_particle.x=randomInRange(0,stage.stageWidth);
mc_particle.id=randomInRange(0,2);
mc_particle.filters=[new BlurFilter(10,10,2)];
mc_particle.addEventListener(Event.ENTER_FRAME,moveSnow);
addChild(mc_particle);
}
}function createCircle(radius:Number):MovieClip {
var mc_circle:MovieClip =new MovieClip();
mc_circle.graphics.beginFill(0xFFFFFF,1);
mc_circle.graphics.drawCircle(0,0,radius);
mc_circle.graphics.endFill();
return (mc_circle);}
function moveSnow(IN_Event:Event):void {
if (IN_Event.target.y>stage.stageHeight) {
IN_Event.target.removeEventListener(Event.ENTER_FRAME,moveSnow);
removeChild(MovieClip(IN_Event.target));
}
IN_Event.target.y += (IN_Event.target.width)/10;
if (IN_Event.target.id==0) {
IN_Event.target.x += (IN_Event.target.width)/30;
} else if (IN_Event.target.id==1) {
IN_Event.target.x -= (IN_Event.target.width)/30;
}
}
/**************************************************************************************************
This function return a random number between min and max number
**************************************************************************************************/function randomInRange(min:Number,max:Number):Number {
var scale:Number=max- (--min);
return Math.ceil(Math.random() * scale + min);
}
}
}
Comments