package util
{
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import org.flixel.FlxG;
	import org.flixel.FlxText;
	
	public class DynamicText extends FlxText
	{
		
		private var dieTimer:Timer;
		
		public function DynamicText(x:Number,y:Number,width:uint,text:String) 
		{
			super(x, y, width, text);
			size = 40;
			color = 0xff222222; 	
			//add text to the current stateaaaaa
			FlxG.state.add(this);
		}
		
		
		
		public function fadeAndDie()
		{
			//fade the text
			dieTimer = new Timer(200, 5);
			dieTimer.addEventListener(TimerEvent.TIMER, fadeText);
			dieTimer.addEventListener(TimerEvent.TIMER_COMPLETE, dieText);
			dieTimer.start();
		}
		
		private function dieText(e:TimerEvent):void 
		{
			dieTimer.removeEventListener(TimerEvent.TIMER, fadeText);
			dieTimer.removeEventListener(TimerEvent.TIMER_COMPLETE, dieText);	
			FlxG.state.remove(this);
		}
		
		private function fadeText(e:Event):void 
		{
			this.alpha = this.alpha -.2;
		}
		
		
	}

}