Code Bits: Set Interval
Oct.05, 2008 in
Flash Actionscript
Set Interval is a fairly simple function that can operate separate of the timeline. Instead of counting frames, it will count milliseconds. This is useful for establishing a timer or making your game the same on all computers, regardless of framerate. Here is an example of it in use:
Timer = setInterval(function () {
seconds -=1;
}, 1000);
Okay, now to explain the code above. First of all, we are creating a new function called Timer. This function is a setInterval. Within the function the variable seconds is told to decrease by 1 every time 1,000 milliseconds goes by. So every second, the variable seconds will decrease by one. That’s it, you’ve just made your first timer.

October 5th, 2008 at 6:05 pm
[...] Free games by Director [...]
October 9th, 2008 at 3:01 pm
If I’m not mistaken, the interval function will be called on the nearest frame when triggered, so you can’t expect it to be fired at exactly the rate you specify.
You could bypass that by using:
var _lastTimer:int = getTimer();
Timer = setInterval(function () {
var now:int = getTimer();
seconds -= (now-_lastTimer)/1000;
_lastTimer = now;
}, 1000);