4 Replies Latest reply on Dec 22, 2009 9:51 AM by kglad

    timer class

    tripleA999 Level 1

      i have start the timer

       

      timer.start();

       

      how I can determine how much miliseconds or seconds passed , since the timer passed

       

      from flash documentation :

      getTimer():int

      Returns the number of milliseconds that have elapsed since Adobe Flash Player was initialized.

       

      getTimer() display since the FlasPlayer starts, how to get value of timer

        • 1. Re: timer class
          kglad Adobe Community Professional & MVP

          the timer class and getTimer() function are not the same.  if you use the timer class, you assign the delay in the constructor:

           

          var t:Timer=new Timer(delayvariable, repeatcountvariable);

           

          or you can use the delay property of the timer:

           

          t.delay = whatever.

          • 2. Re: timer class
            tripleA999 Level 1

            delay will show the delay time between every timer tick

             

            i want to get time between two timer events

             

            like Timer (delay, 5000) >> will tick after every 5 mili second

             

            how i can display , how much timer's time has elapsed OR how much mili seconds has passed  ?

            • 3. Re: timer class
              RossRitchey Level 4

              There are two ways.  One is this:

               

              var before:Number = getTimer();
              
              //after some time has passed - where you want to compare
              
              var after:Number = getTimer();
              
              var timeElapsed:Number = after-before;
              
              

               

              Or:

               

              var t:Timer = new Timer(5000);
              
              t.addEventListener(TimerEvent.TIMER,doTimer);
              t.start();
              
              function doTimer(e:TimerEvent):void
              {
                   trace("Current time elapsed = "+e.target.currentCount*5000);
              }
              
              

               

               

              The first will give you the total number of milliseconds that have elapsed.

              The second will give you the total elapsed in 5 second increments.  Essentially, the timer runs on a delay of 5000 milliseconds, and fires the timer event at each tick.  The event calls the doTimer function.  The e.target.currentCount gives you the number of times the event has fired, which you multiply by the delay to get the total time passed.

               

              The first is more versatile, and allows the time between to be variable, but doesn't allow you to control the amount of time between the start and the calculation.

              The second is great where you want to have something happen every x milliseconds.

               

              It sounds like you are looking for the second method.

              • 4. Re: timer class
                kglad Adobe Community Professional & MVP

                the time between two TimerEvent.TIMER events is give by the delay property of your timer:

                 

                var t:Timer=new Timer(x,y);

                 

                t.delay (=x) is the time in ms between timer function calls.