Skip to main content
Inspiring
May 10, 2011
Question

Timer event too slow?????

  • May 10, 2011
  • 2 replies
  • 822 views

Hi all,


Is flash Timer class bound to frame rate or something because its too slow.

Take this code for example:

package
{
     import flash.display.Sprite;
     import flash.events.TimerEvent;
     import flash.system.System;
     import flash.utils.Timer;
     import flash.utils.setTimeout;
     
     public class MemoryTest extends Sprite
     {
          public var t:Timer;
          public var nm:Number = System.totalMemory;
          public var nc:uint = 0;
          public var date:Date;
          
          public function MemoryTest()
          {
               
               date = new Date();
               trace( "Start time: " + date.seconds );
                    
               t = new Timer( 1, 99999999 );
               t.addEventListener( TimerEvent.TIMER, timerEvent);
               t.start();
               
          }
          
          public function timerEvent(event:TimerEvent):void
          {
               nc++;

               if( nc > 3000)
               {
                    nc = 0;
                    //trace ((System.totalMemory-nm)/1024 + "KiB");
                    t.stop();
               }
               
               date = new Date();
               
               trace( t.currentCount, date.seconds );
          }
     }
}

The nc var should get to 3000 in 3 seconds but it needs about a minute and proccesor is not utilised above 30%. I set delay to 1 milisecond so why is it so slow?

This topic has been closed for replies.

2 replies

relaxatraja
Inspiring
May 12, 2011

1000 milliseconds = 1 second. So make your milliseconds to lower value to increase the speed.

Lee_Burrows
Participating Frequently
May 10, 2011

hi

you cant rely on the timer to be that accurate - its more suited for intervals in seconds.

this article might help you to understand why flash cant deal with timer events of such small intervals: http://www.craftymind.com/2008/04/18/updated-elastic-racetrack-for-flash-9-and-avm2/