Skip to content
All posts
·1 min read

Check your Interval

I was amazed by the inaccuracy of intervals in flash. At least on my system a 1000 millisecond is about 1056 milliseconds. I’m using flash player 8.5 alpha 3…

I was amazed by the inaccuracy of intervals in flash. At least on my system a 1000 millisecond is about 1056 milliseconds. I'm using flash player 8.5 alpha 3 and the swf was compiled with flash 7. On some other systems I've checked this the 1000 ms was acurate but other values were not. On my system some starnge values I've tried, like 546, 682, etc' came out accurate. What gives !?!

Check your interval:

[kml_flashembed movie="http://www.guya.net/blogstuff/intervalinaccuracy/intervalinaccuracy_01.swf" height="80″ width="400″ /]

intervalinaccuracy.zip

Comments (6)

Imported from the original blog

MomoMar 16, 2006

The time interval on my computer is not accurate as well.
I got Falsh MX 2004 and Player 8.
When I checked with 500 ms I got 550, 562, 544, 548, 561, 531, 558 ...
When I checked with 1000 ms I got 1080, 1016, 1000, 1092, 1008, 1000 ...
When I checked with 2000 ms I got 2015, 2014, 2000, 2000, 2000, 2000 ...
It was stable on 2000 for a while.
When I checked with 2020 ms and it wasn't stable.
(always higher than the Interval I wrote).

Momo.

guyaMar 16, 2006

Thanx for your comments momo
You sure did a lot of testing...
:)

malibooApr 26, 2006

Try increase framerate (ieg 120). Also some framerates are "better" than others: my diff. 1000 interval on 30FPS was about 12ms, but for 31FPS it was ~24ms.
Interval isn't executed in separate thread, but AFTER time, and code...

//---code
function a (when)
{
trace(getTimer()-when)
clearInterval(_root.i)
}

_root.i = setInterval(a, 1, getTimer())
var j = 100000; //the switch to 10
while(j--){};

guyaApr 26, 2006

Thanks for your comment maliboo.
As I raise the fps it gets more accurate and at 120 it's pretty good, but I can't run most of my stuff at such high fps.

LarApr 26, 2006

If you declare t1 ( t1 = getTimer(); ) in the onRelease method the results are different from just having it in the interval function. It was much closer to 1 second if the t1 timer was set in the initial release. When run as is the swf generated 1056 aas an average on my machine, when I declared t1 in the onRelease in addition to the interval function I was averaging 1000 - 1013. So the only difference is the t1 being set and not causign the NaN result on the first pass. Not sure what this means for your testing but thought I would share my results.

guyaApr 26, 2006

Thanks for your feedback Lar,
I tried to do what you suggested, I initiated t1 inside the onRelease but the results stayed the same. Maybe I'm not following what you meant.