Skip navigation
Currently Being Moderated

Set interval for milliseconds not working

Aug 24, 2012 6:17 AM

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.

 
Replies
  • kglad
    62,058 posts
    Jul 21, 2002
    Currently Being Moderated
    Aug 24, 2012 6:37 AM   in reply to prodigalmaster

    the fastest that setInterval can loop is, on average, 1000/frame_rate ms where frame_rate is your swf's frame rate.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points