Super-Easy ActionScript Pause Timeline Loop

Its even less complicated than the subject for this post… Download the source if you want it even faster, or read my little explanation. I searched the web looking for a solution for this little problem, of pausing the timeline for a designated amount of time, as to not clutter my timeline with needless static frames, and it seemed everyone’s solutions were too complicated. This is simple as pie. All you need is 3 frames, and a few lines of code.

Frame 1:

var delay = getTimer() + 3 * 1000;

All this is, is a variable called “delay” (or whatever you want to call it) that uses the built-in getTimer() function of flash, to obtain the current time. Then the + 3 * 1000; portion merely adds 3 seconds as the delay by multiplying the number 3 (which represents the number of seconds you want to delay) by 1000, which represents milliseconds, the unit of time measurment used by getTimer(). So to change your pause, you just change 3 to however many seconds you wish to pause the animation.

Frame 2: is empty

**Frame 3: **

if(getTimer() >= delay) {
    gotoAndPlay(this._currentframe+1);
} else {
    gotoAndPlay(this._currentframe-1);
}

This code prevents you from having to label frames and do any needless additional work. All it does, is checks if the current time is greater than or equal to the delay. If it is it moves the playhead forward, continuing the animation, if it isn’t, it moves it back one frame (to empty frame 2, as to not reset the timer), and starts the loop again.

Easy peasy, nice and easy, light and breezy.

XD