4 Replies Latest reply on Nov 30, 2008 2:43 PM by rrhyne

    Using the Timer

    Tones411 Level 1
      I'm trying to use the timer. I can create a timer but now I want to actually do something when the time is up. I'm not sure how exactly to access or use the Timer.timer event. In the code below I get the error: "Can't find the variable: flash". Any suggestions?

      I've been on these two pages:


      Sample Code:

      var TheTimer = false;

      function timerInit(){
      TheTimer = new air.Timer(3000, 0);
      window.nativeWindow.addEventListener(flash.events.TimerEvent.TIMER, onTimer);

      function onTimer(){
      window.nativeWindow.visible = true;
        • 1. Re: Using the Timer
          enorton@adobe Adobe Employee
          Hi Tones411,

          I modified things a tiny bit:


          var trace = window.runtime.trace
          var TimerEvent = window.runtime.flash.events.TimerEvent
          var Timer = window.runtime.flash.utils.Timer

          var theTimer;

          function timerInit(){
          trace("in timerInit()");
          theTimer = new Timer(3000, 0);
          theTimer.addEventListener(TimerEvent.TIMER, onTimer);
          trace("timer started");

          function onTimer(){
          trace("timer triggered");
          theTimer.removeEventListener(TimerEvent.TIMER, onTimer);



          <input type="button" onClick="timerInit()" name="startTimer" id="startTimer" value="Start Timer">


          I hope it helps!
          • 2. Re: Using the Timer
            Tones411 Level 1
            Thank you!

            I was able to get the timer event to work.

            What is the difference between air.Timer and window.runtime.flash.utils.Timer?
            • 3. Re: Using the Timer
              Tones411 Level 1
              I think I know the difference now. Apparently air.Timer is just an alias for window.runtime.flash.utils.Timer.

              You can use the short versions of things such as air.Timer as well as a lot of other things if you include AIRAliases.js in your project.
              • 4. Re: Using the Timer
                rrhyne Level 1
                I realize this post is old, but to add to info on the topic, if you want to reuse the timer,
                don't use:


                instead use:


                ...as it sets the timer to zero, and stops the timer.

                and don't remove the listener.