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

How to run a Spring portlet

java spring jboss portlet

I am new to Spring portlet i am unable to run a sample spring portlet project.. I am trying to run the project from eclipse as run on server on jboss server. My questions are 1. How can we run a po...

iterate .net dictionary as object

c# loops object dictionary key

I have an interesting problem. I need to write a general (I'd use the word "generic" but that would conflict with what I'm after) routine that I can hand an instance of a dictionary object instance...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.