
Back then in the old days of ActionScript 2.0 scripts like the following were just as easy as useful to program sequences of animations (e. g. assembling animations for site sections):
function transitionToolTip():void {
var toolTipAlpha:Tween = new Tween( toolTip, "alpha", Regular.easeOut, 0, 1, .75, true );
toolTipAlpha.addEventListener( TweenEvent.MOTION_FINISHED, handleToolTipTransition );
}
function handleToolTipTransition( e:TweenEvent ):void { … }
Just to make things clear: The ActionScript 3.0 garbage collector does a good job in deleting these local variables. Obviously the ActionScript 2.0 garbage collector should have done this way, too.
In most cases one does not want to stop or modify tweens after firing them, thus one won't need a reference to the exact tween ever again. The next function would be triggered after the tween has finished. Great!
But, nowadays things are different. ActionScript 3.0's garbage collector seriously and unrelentingly works on what it is supposed to work: deleting everything with a lack of relation. In the sample case, shown above, this clearly means that the variable toolTipAlpha, declared with local scope of function transitionToolTip will be deleted – taking along our tween if the garbage collection cycle is awkward. In consequence our tween will not play to its end.
One solution would be the declaration of a class level or global variable to store the reference to the tween. This would look something like this:
var toolTipAlpha:Tween;
function transitionToolTip():void {
toolTipAlpha = new Tween( toolTip, "alpha", Regular.easeOut, 0, 1, .75, true );
toolTipAlpha.addEventListener( TweenEvent.MOTION_FINISHED, handleToolTipTransition );
}
function handleToolTipTransition( e:TweenEvent ):void { … }
All the samples are in short form and not taken from real-life ActionScript 3.0 projects thus may not work properly. They are inserted for illustration purposes to show up possible problematics.
A far more elaborated description of the coexistence of tweens, variables and the garbage collector can be found on Scott Morgan's blog in the article AS3 Garbage Collection, the reason your tweens are ending early.
via Scott Morgan's blog – http://www.scottgmorgan.com/
Sorry! Our Ping- and Trackback is not yet working.