0
votes

I need to make an animation with numerous objects (around 500) flying from left to right, with different delay, duration and destination. However I need to run another function once all the objects have been already arrived at their destination.

I have tried to make an loop check every time when an object complete its flight. that is:

...
for(var i:int = 0; i < objs.length; i++)
    Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});
...

private function CheckAllComplete():void
{
    for(var i:int =0 ;i < objs.length; i++)
    {
        if(Tweenlite.getTweensOf(obj[i]).length > 0)
            return;
    }
    ... // if all the flights complete
}

But I think it is very bulky and worse for CPU.

So, my question is, How can I consider all the objects as one tween and just add onComplete to solve the problem?

something like:

var tween:*;
for(...)
    tween.add(obj[i], duration, {...});
tween.onComplete = CompleteCallback;
1
I believe you can create a index and increase it every time the a Tween is completed and you check if this index is equals your number of objects. If so, you can stop the process.gabriel

1 Answers

0
votes

Based on your own code (I didn't check to see if works or has any bug)

 private var tweenObjectsIndex:uint = 0;
 private var numObjects:uint = objs.length;

 for(var i:int = 0; i < numObjects:uint; i++)
 Tweenlite.to(obj[i], duration, {delay:delay, x:destination.x, y:destination.y, onComplete:CheckAllComplete});

  private function CheckAllComplete():void
  {
       tweenObjectsIndex++;
       // if all the flights complete
       if(tweenObjectsIndex == numObjects) // do something
  }