Reputation: 11662
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);
Upvotes: 2
Views: 1124
Reputation: 329
You can also create an array in the scope of your class, then just push tweens onto that array. Although this might cause the tweens in the array to never get garbage collected, even after they finish, so you might want to empty the array yourself at points in which you know all the tweens have finished.
Upvotes: 1
Reputation: 6108
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.
Upvotes: 4
Reputation: 11662
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.
Upvotes: 3