When making long Flash Movies that mostly rely on keyframing in the timeline, I’ve always found it cumbersome to get the timing right.

Moving the keyframes back and forth in the timeline gets less than efficient when you get more than a few layers, and the process is error-prone and makes experimenting with different timing hard. Inserting a little timeline ActionScript which would wait for a given period of time would make things a lot easier. You’d only have to change the delay time to change the timing of the movie. But for some reason googling this issue never gave any satisfying results – although the solution is quite simple, now I know it.

I simply use setTimeout. I know that this is not supported in AS3, but somehow it still works in simple AS3 Flash movies.

Insert at any given frame the following script:

stop();
setTimeout(play, 2000);

2000 is the number of milliseconds your want to delay, in this case 2 seconds.

If the setTimeout command gives you trouble, or if you’re an ActionScript purist, you can place the following functions on the first frame of your timeline instead:

function setDelay(milliseconds) {
stop();
var timer:Timer = new Timer(milliseconds, 1);
timer.addEventListener(TimerEvent.TIMER, timerStop);
timer.start();
}

function timerStop(e:TimerEvent):void {
play();
}

At the frame you want to delay you place:

setDelay(2000);

2000 is the number of milliseconds your want to delay, in this case 2 seconds.

Posted Monday, February 16th, 2009 at 2:20 pm
Filed Under Category: AS3, Coding, Flash
You can leave a response, or trackback from your own site.

0

Leave a Reply