AS2 and AS3.






This is a special-purpose method that updates the engine's internal clock, and avoid breaking animation due to external code that freezes the player for a certain time (for example, more than 50 miliseconds). So if you want to start new animations immediately after some very complex code is executed, you should call this method first.

The way Tweener works is that, instead of reading the current time (via the getTimer() function) every time a new animation starts or is updated, it reads the time every time a new frame starts. This way, tweenings started or updated at different times (but on the same frame code) can be kept synchronized and provide a smoother playback (for example, when executing a series of tweenings on different objects on a loop, all of the objects will move at the same time, instead of being slightly separated in time). This feature works as a time grid of sorts, where the time used by Tweener snaps to the time the frame actually started, providing a more accurate frame drawn even if a less accurate time read.

However, if you happen to have some very complex code being executed somewhere - say, sorting through a long list of datasets, parsing a long XML, or manipulating a big bitmap - it means that once Tweener code is executed, the time it'll be using as a basis will be too far behind the current time. If you are starting animations with addTween right after your complex code has been executed, it will give you the impression that the animation actually snapped forward to a certain position before continuing smoothly - sometimes even reaching their final values without executing, depending on how much time was lost to the complex code that froze the player before.

What this method do, then, is simply force an update on the engine timer, making it read the current time again, as if starting a new frame, and thus making the animation play smoothly, ignoring the frames lost due to code execution.

Don't be fooled, however; this is a last-resort solution to an external problem, and one that should be used very rarely. Instead, your best choice is usually to fix the complex code itself, as it can risk more of the framerate and overall user experience than simply causing snaps on Tweener animation.

Only use this method when you're not able to fix the external code that is freezing the Flash player.




// Updates the timer before a new Tweening to make sure it starts smoothly
for (var i:Number = 0; i < 31337; i++) {
	// do some very complex code that freezes the player for a while
Tweener.addTween(myMC, {_x:100, time:1, transition:"easeoutquad"});
Tweener.addTween(myOtherMC, {_y:100, time:2, transition:"easeoutquad"});