Escape Theory Programming, Flash and Gaming For Life…

27May/101

Tween Class Tweens Freezing Halfway Through Animation

When creating multiple Tween instances using the Flash Tween classes, animations randomly freeze.

Error type: Bug

Error class: -

How to Induce error:

Using the built-in Flash Tween classes, create multiple tweens on one or more objects.

When these tweens are all firing , Flash randomly 'cleans up' the tween instance while it is still animating. In effect, the animation appears to freeze.

Further tween instances can unfreeze the animation, but clearly this is too annoying to ignore!

Solution:

We can store the tween instance in an Array, and clear the instance when the tween is no longer required. This forces the Flash garbage collector to stop destroying your tween instance:

var tweensArray:Array = []; var tween_count:Number = 0; function tweenFunc():void{ tweensArray[tween_count] = new Tween(myObj, "alpha", Strong.easeOut, myObj.alpha, 1, 0.5, true); tween_count++; }
function fadeContent(showWhichNumber):void{

//tween class has FREEZING bug, it removes tweens before they complete when many tweens occur - this is RANDOM.
//in order to stop the removal, we store the tweens in an array, and wipe them out on each changeContent call.
//remove this fix at your own risk!

if(currentContentNumber == showWhichNumber){
tweensArray[tween_count] = new Tween(this['content'+ (showWhichNumber).toString()], "alpha", Strong.easeOut, this['content'+ (showWhichNumber).toString()].alpha, 1, 0.5, true);
tween_count++;
}else{
tweensArray[tween_count] = new Tween(this['content'+ (showWhichNumber).toString()], "alpha", Strong.easeOut, this['content'+ showWhichNumber].alpha, 0, 0.5, true);
tween_count++;
}
}

Comments (1) Trackbacks (0)
  1. Here’s a comparison / benchmark for tweening classes. I guess this is why TweenLite/Max is amongst the most popular out there.
    http://www.greensock.com/tweening-speed-test/

    (not sure if this is biased though)


Leave a comment

(required)

No trackbacks yet.