3 Replies Latest reply on Jun 2, 2014 6:30 AM by kglad

    Timer - How to stop it?

    melfs

      Hello,

      I am learning how to make a timer to my game. It is something like "Who wants to be a millionaire?" I have 15 questions. There is timer for each question:60 seconds.... When I click on an answer I go on next frame, but my timer does not stop. What should I add ( and where ) to stop my timer when I clik an answer? My code for the timer is:


      timer = 60;

      countdown = function(){

      _root.timer--;

      if(_root.timer<=0){

        gotoAndPlay(20); stop();

      }

      }

      countdownInterval = setInterval(countdown,1000);

        • 1. Re: Timer - How to stop it?
          kglad Adobe Community Professional & MVP

          use clearInterval:

           

          clearInterval(countdownInterval);

          • 2. Re: Timer - How to stop it?
            melfs Level 1

            Thank you! Where should I add it in my code ? Sorry for the question but this is my first time trying to do a game in Flash.

            • 3. Re: Timer - How to stop it?
              kglad Adobe Community Professional & MVP

              you should always add it just before setting it.  that prevents a major difficult-diagnose-problem that you have yet to encounter but almost certainly eventually will.

               

              and you should add it when you want to stop the interval.

               

              from my understanding of your setup, you only want that timer to execute once on each frame and you probably want it to stop when the user answers a question.  so, you should use clearInterval when a user answers the question and when the countdown executes.

               

              p.s.  you can uset setTimeout for a timer that only executes, at most, once.  that would eliminate the need to use clearTimerout in countdown, but you would still use it when the user answers a question.