I am trying to construct a timed loop… so far without success.
What I need is a loop where iteration 0 + i + 1 starts a few seconds after iteration 0 + i. I tried putting a timer inside the loop but the loop seems to simple skip the timer instead of executing it sequentially before starting the next iteration. Here is the code snippet:
var iTimer : Timer;
for( var i:int = 0; i < 2; i++ )
{
trace( i + " i iterations" );
iTimer = new Timer( 1000 );
iTimer.addEventListener( TimerEvent.TIMER, iLoop );
iTimer.start( );
function jLoop( evt:TimerEvent ):void
{
trace( i + " i iterations" );
iTimer.removeEventListener( TimerEvent.TIMER, jLoop );
iTimer.reset( );
}
}
The loop does not seem to wait for jLoop() to be executed. It speeds ahead onto the next iteration, instantiating a new timer and thus screwing up the timing of the iterations. I have tried different things like putting break and continue statements in there but to no avail. Anyone got an idea?