A Simple Pause Function in Actionscript 3

Just a quick function that you can use in your library of tricks to simulate pausing in Actionscript 3.

public static function pause(timeInSeconds:int, functionToCall:Function):void {
    var timer:Timer = new Timer(timeInSeconds * 1000);
    timer.addEventListener(TimerEvent.TIMER, callFunction, false, 0, true);
    function callFunction(event:TimerEvent):void {
        timer.removeEventListener(TimerEvent.TIMER, callFunction);
        timer = null;

The function takes 2 arguments:

timeInSeconds – how many seconds to wait before calling the function
functionToCall – the function to call after the given time has passed

example usage (assuming that you drop this function into a class called Utilities:

private function gameWinTriggered():void{
     // player just dropped the last piece on the game board,
     // but we want to wait a second before showing the win screen

private function showWinScreen):void{
     trace('You Win!');

That’s all there is to it. Really handy for instances like these when you want to wait before a transition as to not jar the player with instant changes.

One thought on “A Simple Pause Function in Actionscript 3”

  1. Hello Sir,
    First of all Thanks for great job.I am Flex developer since last 2 year.
    I have some doubt regarding to flex technologies.since Flex donate to appache by adove.so what do you think about this should we switch to another technologies or there is any scope of flex.

Leave a Reply