Efecto de Nieve en ActionScript 3 | Phoxer.com
Efecto de Nieve en ActionScript 3
24/07/2009

I Developed a Snow effect

First we must import the class and implement it in this way. (Very easy)

import phoxer.Sprites.BackGrounds.Snow;
 
var snw:Snow = new Snow(this,0,0,100);
snw.repeat=true;
snw.area = new Rectangle(0,0,550,400);
 
snw.startRender();


Here is my Snow Class:

/**
by .:{PHOXER}:.
http://www.phoxer.com
v 1.2;
*/
package phoxer.Sprites.BackGrounds{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.geom.Rectangle;
	import flash.utils.Timer;
 
	import phoxer.ChildsManager.DeleteClips;
	import phoxer.Numbers.Random;
	public class Snow extends Sprite{
		private var timer:Timer;
		public var area:Rectangle;
		public var repeat:Boolean=false;
		public function Snow(cont:Object,nx:int=0,ny:int=0,dl:int=500){
			super();
			cont.addChild(this);
			this.x=nx;
			this.y=ny;
			timer = new Timer(dl,0);
		}
 
		private function addItem(e:TimerEvent):void{
			var item:SnowBall = new SnowBall();
			item.sf=area.y+area.height;
			item.tm=0;
			item.sp=1+Math.random()*2;
			item.vt=-1.5+Math.random()*(1.4*3);
			var sc:Number = Random.getRandom(0.3,1);
			item.scaleX=sc;
			item.scaleY=sc;
			item.alpha=sc;
			item.x=Random.getRandom(area.x,area.width,true);
			item.nx=item.x;
			item.y=area.y;
			item.ny=item.y;
			this.addChild(item);
		}
 
		public function startRender():void{
			this.addEventListener(Event.ENTER_FRAME,render,false,0,true);
			timer.addEventListener(TimerEvent.TIMER,addItem,false,0,true);
			timer.start();
		}
 
		public function stopRender(dl:Boolean=true):void{
			timer.stop();
			this.removeEventListener(Event.ENTER_FRAME,render);
			timer.removeEventListener(TimerEvent.TIMER,addItem);
			if(dl){
				DeleteClips.deleteAll(this);
			}
		}
 
		private function render(e:Event):void{
			for(var i:int=0;i<this.numChildren;i++){
				var item:SnowBall = this.getChildAt(i) as SnowBall;
				item.y  += item.sp;
   				item.x += item.vt;
   				if(repeat){
					if (item.x>(area.x+area.width))  {
					    item.x = area.x;
					}else  if (item.x<area.x)  {
					    item.x = area.x+area.width;
	   				}
   				}
				if(item.y>=item.sf){
					this.removeChild(item);
				}
			}
		}
	}
}