4 Replies Latest reply on Aug 12, 2006 1:25 AM by m2ming

    countdown timer....

    lostinscript
      Hi,

      I have a timer that counts backwards and when it reaches 0 performs other actions (such as go to a different screen). Counting down is not a problem, its when it reaches 0 it wont do anything, ive been fiddling with this for a while and cant work it out....anyone got any ideas. The code is on the main timeline with a dynamic textfield on stage (called myTime).

      Thanks....

        • 1. Re: countdown timer....
          blemmo Level 1
          Hi,

          guess it's just a typo: if (mySeco unds <= 0) should be if (mySeconds <= 0).
          The interval keeps on running, so it's better to delete it when it reaches 0:
          function wait() {
          mySeconds--;
          if (mySeconds <= 0) {
          trace("times up");
          clearInterval(myTime);
          }
          }
          myTime = setInterval(wait, 1000);

          hth,
          blemmo
          • 2. Re: countdown timer....
            lostinscript Level 1
            lol.....i am so dumb sometimes...

            Thanks blemmo...
            • 3. Re: countdown timer....
              blemmo Level 1
              **it happens...

              you're welcome.
              • 4. Re: countdown timer....
                m2ming
                hi, can anyone help to explain this script, line by line, as in what does " var", "secInd", stands for, when to use it, how to use it etc...

                stop();
                var timerID:Number;
                var secInd:Number =0;
                var maxTime:Number = 60;

                startTimer();

                function updateTimer(){
                secInd = maxTime--;

                timer_txt.text = String(secInd);

                if (secInd == 0){
                trace("game over");
                stopTimer();
                trace("this = " + this);
                gotoAndPlay("gameOver");
                }
                }
                function startTimer():Void{
                timer_txt.text = String(maxTime);
                timerID = setInterval(this, "updateTimer", 1000);
                }
                function stopTimer():Void{
                clearInterval(timerID);
                }