Well just had one of those weekends when you go home, pull out an old machine and test your latest creation, only to find it runs a little slow… Made some simple tweaks to make sure that people who play the game on a slower machine can still play it fairly (i.e. so if time is a factor then to compensate for the slower machine). I then built in a calculation to test the efficiency of the game so I could potentially monitor my users experience of the game to get a sample of its efficiency.
This is when I noted at 25 frames per second, my setInterval (set at 40ms ,1000/25) was only being called 60% of the time. Switching to 50 frames per second had little of no impact on the efficiency either. This lead me to believe that setInterval did not run independently of the frame rate and that I should use onEnterFrame instead. The flash manual had this to say about setInterval -
If interval is less than the SWF file’s frame rate (for example, 10 frames per second [fps] is equal to 100 millisecond intervals), the interval function is called as close in time to the value of interval as possible. Executing long, memory-intensive scripts during an interval causes delays. If the function being called initiates a change to visual elements, you should use the updateAfterEvent() function to make sure that the screen refreshes often enough. If interval is greater than the SWF file’s frame rate, the interval function is called only after interval has expired and the playhead has entered the next frame; this minimizes the impact each time the screen is refreshed.
Therefore when updates are made on a small interval you should always use onEnterFrame and not setInterval – when we switched the same code to onEnterFrame the efficentcy jumped to 98%, even though the interval was matched to the frame rate the performance drop was considerable – I would even be a bold as to say unless your required interval is 10x the frame fate interval you should stick to onEnterFrame as the method instead.