Question

I'm developing a page with a flash embeded, I want to set the frameRate to 0.01(the lowest) when the page loses focus so that flash will not eats too much cpu. I have a timer to display a countdown to a specific date on the page, I set it to trigger every 1000ms as all the countdowns do.

This works when the frameRate is 12, not perfectly though, it's not so accurate as 1000ms but something near that, like 950ms or so. But when the frameRate is 0.01, when the page loses focus, the timer triggers more frequently than that a countdown should do.

I logged getTimer() at every TimerEvent.TIMER, here's some info below:

203702 204452 205202 205952 206702 207452 208202 208952

How can I fix this? Or the simplest way is just do not drop the frameRate?

Was it helpful?

Solution

Timers are not that perfect and not that dependable on frame-rate. Adobe's reference:

You can create Timer objects to run once or repeat at specified intervals to execute code on a schedule. Depending on the SWF file's framerate or the runtime environment (available memory and other factors), the runtime may dispatch events at slightly offset intervals. For example, if a SWF file is set to play at 10 frames per second (fps), which is 100 millisecond intervals, but your timer is set to fire an event at 80 milliseconds, the event will be dispatched close to the 100 millisecond interval. Memory-intensive scripts may also offset the events.

Best practice here is to reset the timer when focus is lost :) It will stop, but remain as an instance, so later on (when on focus again) you can simply use start() to get things running again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top