ActionScript does not have a sleep or delay function. Like JavaScript, you can use setTimeout()as follows:
function trigger():void { setTimeout(doIt, 1000); }
function doIt():void { Alert.show("done!"); }
As soon as you associate the function trigger()with any event, such as “click”, when the event appears, a notification window will appear after 1 second.
There are also functions setInterval()and clearlnterval()that you can use to repeat. However, in this case, it is recommended to use a class flash.utils.Timer.
private var myTimer:Timer;
private function init():void {
myTimer = new Timer(5000, 1);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
myTimer.start();
}
public function timerHandler(event:TimerEvent):void {
Alert.show("I was delayed!");
}
user1271208
source
share