Would this code delay the time between every time the loop gets fired?
while (coin.x > objYEnemy.x) {
var delay:Timer = new Timer(100, 1);
delay.addEventListener(TimerEvent.TIMER, runOnce);
delay.start();
function runOnce(event:TimerEvent):void {
coin.x -= 1;
delay.stop();
}
}
Not really. Your loop will keep running over and over (for at least 100ms while your timer waits to fire), creating a new timer every time and creating a memory leak because your timers will never get disposed of on account of their event listener. Since your runOnce is an anonymous function, it will also get run a whole lot of times for every timer that gets created.
Without the knowing exactly what you’re trying to accomplish, it would seem what you’ll want to do is have the timer tick handler be the loop function.