why do tweens stop randomly?

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);

Answers


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.


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.


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.


Need Your Help

My website shows up as a blank page on my desktop

html css wordpress website

I have been developing a wordpress theme on my laptop and all is well, however when I checked it on my desktop today all that loads is a blank page. I have asked a couple friends to see if it load...

Characters lost on simple assignment

arrays string powershell variable-assignment powershell-v3.0

I'm having a very strange issue concatenating a simple string in powershell.