3 Replies Latest reply on Jun 21, 2007 8:42 AM by hciguy

    Urgent Help Needed for a Countdown Timer

    rallen2006
      Please please please help, i am stuck!

      I need to create a simple timer that will count down from say 32 seconds to zero. I want this to appear and start once a user has clicked something. I actually want it embedded in this bit of code:

      on (click) {
      this._parent.micrometer_one.play()
      }

      and also appear if the student clicks on the video play part too.


      Any help greatly appreciated i have no idea on timers or anything :(
        • 1. Re: Urgent Help Needed for a Countdown Timer
          MaxManNH Level 2
          Timer code is pretty simple if you use the setInterval function.

          var counter:Number = 0;

          intervalID = setInterval(timerFunction, 1000); //can't remember if the function to
          //call needs to be in quotes

          function timerFunction()
          {
          counter++;
          if(counter > 32)
          {
          //counter has reached 32 seconds do something here.
          clearInterval(intervalID) //this will stop the setInterval from firing
          }
          }
          • 2. Re: Urgent Help Needed for a Countdown Timer
            rallen2006 Level 1
            thanks for your reply.

            How would that tie in wiht this code :

            on (click) {
            this._parent.micrometer_one.play()
            }


            Sorry am i complete beginner :(
            • 3. Re: Urgent Help Needed for a Countdown Timer
              hciguy Level 1
              on (click) {
              this._parent.micrometer_one.play();

              // initiate the timer
              var counter:Number = 0;
              intervalID = setInterval(timerFunction, 1000); //can't remember if the function to
              //call needs to be in quotes
              }

              function timerFunction()
              {
              counter++;
              if(counter > 32)
              {
              //counter has reached 32 seconds do something here.
              clearInterval(intervalID) //this will stop the setInterval from firing
              }
              }

              I am guessing this is in AS 2.0 because Timers are different in AS 3.0.