package { import flash.display.MovieClip; import flash.geom.ColorTransform; import flash.geom.Transform; import flash.events.*; public class Pat extends MovieClip { public var xvel:Number = 0; public var yvel:Number = 0; public var xf:Number = 0; public var yf:Number = 0; public var lifetime:int; public var lifeRem:int; public function Pat(x:int, y:int, xvel:Number, yvel:Number, lifetime:int, col:int) { this.xf = x; this.x = x; this.yf = y; this.y = y; this.xvel = xvel; this.yvel = yvel; this.lifetime = lifetime; lifeRem = lifetime; var ct:ColorTransform = new ColorTransform(); ct.color = col this.transform.colorTransform = ct; this.addEventListener(Event.ENTER_FRAME, move); } public function move(e:Event):void { lifeRem--; if (lifeRem == 0) { parent.removeChild(this); this.removeEventListener(Event.ENTER_FRAME, move); return; } if (lifeRem < 0) return; // later, add color changing code here based on lifeRem / lifetime and original color // maybe also slow it down or make it turn a bit by messing with velocity xf += (lifeRem/lifetime)*xvel; yf += (lifeRem/lifetime)*yvel; //xvel += xvel * (Math.random() - .5 ) / 2; //yvel += yvel * (Math.random() - .5 ) / 2; var r:int = Math.random() * 256; var g:int = Math.random() * 256; var b:int = Math.random() * 256; var rgb:int = r << 16 | g << 8 | b; var newColor:ColorTransform = new ColorTransform(); newColor.color = rgb; this.transform.colorTransform = newColor; x = int(xf); y = int(yf); } } }