0
votes

I'm making a simple helicopter game to try and get into making flash games. I wanted to make a countdown timer that will count down from 3 seconds, then start the loop, but I'm not sure how to go about is. I don't use the frames in flash, rather I use action script (3) to make an "ENTER_FRAME" loop, if that helps. It looks like this:

addEventListener(Event.ENTER_FRAME, mainLoop);

I'm sure I need to put the timer above it, I'm just not sure how to make a timer. Any advice will probably help, as I'm new to AS3, thanks.

2
Try a Timer. - akmozo

2 Answers

0
votes

To make a countdown timer, you can use a Timer, like this :

trace('3');

// create a timer with : delay: 1 second, repeats: 3
var timer:Timer = new Timer(1000, 3);   
    timer.addEventListener(
        TimerEvent.TIMER,
        // on every repeat
        function(e:TimerEvent):void {                   
            trace(Math.abs(timer.currentCount - 3));  // gives : 2, 1, 0
        }
    )
    timer.addEventListener(
        TimerEvent.TIMER_COMPLETE,
        // at the timer end 
        function(e:TimerEvent):void {
            // do other instructions
            trace('go');
        }
    )
    // start the timer
    timer.start();

Hope that can help.

-1
votes

I hope i can help you with your code. What im getting is that you try to make 3 seconds count down then start somewhere. yes you need a timer :

    var theTime:Timer 
    theTime = new Timer(countDownLoading*1000); //1000 is in milisecond

    var countDown = 1;
    var totalCountDown = 3; // How long it'g gonna count
    var countDownLap = totalLoading;

    theTime.addEventListener(TimerEvent.TIMER,tick); //adding timer event
    function tick(e:TimerEvent){
        if(countDownLap == 0)//if the cound down is 0
        {
            time.stop();
            gotoAndStop(2);
            trace("Finish counting");
        } else { //not counting down yet, then lets count
            countDownLap = countDownLap - countDown; // 
            trace(countDownLap);
        }
    //timer goes like the ticking clock so if the count down is not 0.
    //everytime the ticking starts the cound down (3) - 1
    }

I hope this help.