views:

527

answers:

2

With code like the following, sometimes the child controls correctly finish their animation and sometimes they stop at random places in the middle. Why don't they work correctly?

var t:Tween;
t = new Tween(child1,"x",Elastic.easeOut,0,100,2,true);
t = new Tween(child1,"y", Elastic.easeOut,0,100,2,true);
t = new Tween(child2,"x",Strong.easeOut,300,400,1,true);
t = new Tween(child2,"y", Strong.easeOut,300,400,1,true);
+3  A: 

Each tween must be assigned to a separate variable in global scope. The following code behaves reliably:

var t1:Tween = new Tween(child1,"x",Elastic.easeOut,0,100,2,true);
var t2:Tween = new Tween(child1,"y", Elastic.easeOut,0,100,2,true);
var t3:Tween = new Tween(child2,"x",Strong.easeOut,300,400,1,true);
var t4:Tween = new Tween(child2,"y", Strong.easeOut,300,400,1,true);

It would appear that when a variable is re-used, the tween that is no longer referenced may get garbage collected or otherwise halted in the middle of its work.

The same problem can occur if you use separate variables but declare them in the local scope of a function instead of in the global scope of your frame.

Eric
+3  A: 

Additionally, try using an free/open source tween engine rather than the one packaged with Flash. Two very popular ones are TweenLite and Tweener. They offer greater performance and more functionality/options.

Matt W