package bontos { import flash.events.Event; import mx.controls.Image; import spark.components.Group; public class Snow { private var w: Number; private var h: Number; //private var max_snowsize: int = 10; private var snowflakes: int = 25; private var snowHolder: Group; private var arrImgSrcs: Array = []; [Embed(source="assets/img/SnowFlake_Vectors.png")] [Bindable] private var imgCls: Class; [Embed(source="assets/img/SnowFlake_Vectors10.png")] [Bindable] private var imgCls10: Class; [Embed(source="assets/img/SnowFlake_Vectors12.png")] [Bindable] private var imgCls12: Class; [Embed(source="assets/img/SnowFlake_Vectors13.png")] [Bindable] private var imgCls13: Class; [Embed(source="assets/img/SnowFlake_Vectors14.png")] [Bindable] private var imgCls14: Class; public function Snow(snowHolderL: Group) { arrImgSrcs = [imgCls, imgCls10, imgCls12, imgCls13, imgCls14]; snowHolder = snowHolderL; w = snowHolder.width; h = snowHolder.height + 25; init(); } private function init(): void { var img: Image; for(var i: int = 0; i < snowflakes; i++ ) { img = new Image(); img.source = arrImgSrcs[Math.floor(Math.random() * arrImgSrcs.length)]; img.alpha = 0.3 + Math.random()*0.7; img.x = -(w*0.5) + Math.random()*(1.5*w); img.y = -(h*0.5) + Math.random()*(1.5*h); img.data = { k: Math.random()*1.5 + 1, wind: Math.random()*3.5 - 1.5 } img.addEventListener(Event.ENTER_FRAME, onEnterFrame); snowHolder.addElement(img); } } private function onEnterFrame(ev: Event): void { var img: Image = ev.currentTarget as Image; var xL: Number = img.x; var yL: Number = img.y; yL += img.data.k; xL += img.data.wind; if(yL > h+10){ yL = -20; } if(xL > w+20){ xL = -(w*0.5) + Math.random()*(1.5*w); yL = -20; }else if(xL < -20){ xL = -(w*0.5) + Math.random()*(1.5*w); yL = -20; } img.x = xL; img.y = yL; } } }