Saturday, August 2, 2008

Delay and jump to new frame

A frequent problem is how to delay the timeline, for a given period of time, and then branch to another frame once the delay is up.

A bespoke function and the setTimeout function can be combined to do this with ease:

var delay:Number = 1000;
var frameNumber:Number = 10;
function playFrame(frameNumber:Number)
setTimeout(playFrame, delay, frameNumber);

delay is the length of time before the setTimeout calls the playFrame function. This is expressed in milliseconds.
frameNumber is the target frame to jump to once the delay is over.

The same principle works equally as well with frame labels:

var delay:Number = 2000;
var frameLabel:String = "menu";
function playFrame(frameLabel:String)
setTimeout(playFrame, delay, frameLabel);

No comments: