1 Reply Latest reply on Aug 24, 2012 6:37 AM by kglad

    Set interval for milliseconds not working

    prodigalmaster Level 2

      Hello. When I increment a counter every millisecond with setInterval, it is too slow.

      Here is the code:

       

      var second:Number = 0; 
      var millisecond:Number = 0;
      
      function updateMil(){
                millisecond ++;
      }
      setInterval(updateMil,1);
      
      function updateSec(){
                second++;
                trace(millisecond+", "+second);
      }
      setInterval(updateSec,1000);
      

       

      and outputs:

       

      133, 1

      255, 2

      387, 3

      515, 4

      647, 5

      779, 6

       

      where the seconds on the right updates every second correctly. Surely the milliseconds on the left should be in 1000 increments because 1000 milliseconds make a second.