Undocumented setTimeout()

I buddy of mine Danny Lee tipped me off to this bit of code that was left out of the Flash documentation. It is called setTimeout, and it is probably one of the most useful things I have seen since…well functions.

To use it you just say something like:

setTimeout(nextFunction,1000);

All that does is pause the timeline for 1000 milliseconds (1 second) and then execute a function called nextFunction. You can also pass parameters at the end. All that being said I made this pauser for people to use. Mostly useful for simple timeline animations:

// Pauser Function
function pauser (timeline, duration)
{
	trace ("Paused " + timeline);
	timeline.stop ();
	pauseTimer = setTimeout (unPause, duration, timeline);
}
function unPause (timeline)
{
	trace ("Un-paused " + timeline);
	timeline.gotoAndPlay (timeline._currentframe + 1);
}
// to call it say something like:  _root.pauser (this,1000);
// to clear it: clearTimeout(_root.pauseTimer);

You are just calling the “pauser” function and passing it which timeline you are pausing (normally you would just say “this”, and then the amount of time to pause that timeline. It then pauses that timeline, and at the end of the “duration” you set it will unpause itself and advanced to the next frame (timeline._currentframe + 1).

I hope someone finds this useful. Let me know of any modifications to make this better.