Saturday, March 28, 2009

A simple timer event

So many times one searches for a simple timer event. Say I want to do some thing after few seconds then one requires a timer so here it goes..

public var t:Timer;

public function init():void{
//This can be any function...

t = new Timer(3000); //3000 is the timer interval which corresponds to 3 secs
t.start();
t.addEventListener(TimerEvent.TIMER,targets);//So after 3 secs it goes to the targets function
}

public function targets(event:Event):void{
t.stop();//Stop the timer
Alert.show("Ta da I am here after 3 secs");
}