3 Replies Latest reply on Apr 23, 2007 2:34 PM by Greg Dove

    Reseting CountDown Timer

    briiiiin Level 1
      Hi,
      Well below is my code, its a countdown timer that does some functions on reaching 0:

      //TIMER to CLEAR SCREEN
      displayTime = 10;
      countDown = function () {
      displayTime--;
      if (displayTime == 0) {
      clearInterval(timer);
      _root.line.clear();
      left._visible = false;
      displayTime = "Cleared";
      }
      };
      timer = setInterval(countDown, 1000);

      The problem is, i want it to reset and start counting down again everytime it reaches 0
      Can anyone see a way throught this?
      Thnx.


        • 1. Re: Reseting CountDown Timer
          Greg Dove Level 4
          Immediately, or as needed?
          IMMEDIATELY:

          //TIMER to CLEAR SCREEN
          displayTime = 10;
          countDown = function () {
          displayTime--;
          if (displayTime == 0) {
          //clearInterval(timer); //don't cancel the timer if you just want it to 'loop'
          _root.line.clear();
          left._visible = false;
          displayTime = 10; //make it 10 again
          }
          };
          timer = setInterval(countDown, 1000);

          AS NEEDED:
          //TIMER to CLEAR SCREEN

          countDown = function () {
          displayTime--;
          if (displayTime == 0) {
          clearInterval(timer);
          timer = null; // flag the interval as not active
          _root.line.clear();
          left._visible = false;
          displayTime = "Cleared";
          }
          };

          function startCountDown(from) {
          if (timer != null) clearInterval(timer) //cancel any existing countdown
          displayTime = from; //just in case you want more than 10
          timer = setInterval(countDown, 1000);
          }

          startCountDown(10);
          • 2. Re: Reseting CountDown Timer
            briiiiin Level 1
            Brilliant, wow that was superfast. Works perfect
            Thanx alot GWD
            • 3. Re: Reseting CountDown Timer
              Greg Dove Level 4
              you're welcome