some code;
sleep(); // Delay for x amount of time
some more code;
So one needs to use the timer class to achieve delays and such, which means that if you come from a multi thread background and are accustomed to putting in a sleep(), you would have to rethink your approach.
The timer usage is simple enough:
import flash.events.TimerEvent;
import flash.utils.Timer;
// Create the timer, generate a tick every 500 millisec, Timer ends after 2 seconds.
var new_timer:Timer = new Timer(500, 2);
// function on_tick() will be called every 500 millisec
new_timer.addEventListener(TimerEvent.TIMER, on_tick);
// function timer_complete will be called once the timer expires, 2 secs in this case
new_timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_complete);
// Start the timer
new_timer.start();
function on_tick(event:TimerEvent):void {
// some code
}
function timer_complete(event:TimerEvent):void {
// some code
}
Note the parameters, event:TimerEvent in the functions on_tick and timer_complete, those are needed else the implementation will not work.