I'm working in an educational software, mostly developed using Flash AS3, and we have a chronometer which shows different values through different users. Example: Two users s开发者_如何学JAVAtarting the chronometer at same time, but along some minutes of usage, they have different values.
The current implementation uses Timer class, causing this to happen, obviously due the different average speed of each computer.
I already have an idea in mind, but I would like to have some theoretical suggestions. Thanks in advance.
The Timer class is not very accurate. From the docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html
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.
If you're looking for a relative time since the start of your application, use flash.utils.getTimer(). http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/package.html#getTimer%28%29
If you want to do more sophisticated timing, you can use the Date class. http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Date.html
精彩评论