Alexander Kolarov
Alexander Kolarov

Reputation: 855

Motions with tweens one after another in Actionscript?

I have some problems with motions and tweens: I want move my sprite to to the bottom right corner (800,600) then to the top left corner (0,0). But my tweens arent waiting each other.

motion.toBotCorner(currentSprite);
motion.toTopCorner(currentSprite);

And this is in my Motion class:

        public function toBotCorner(currSpr:Sprite):void {
            TweenLite.to(currSpr, 3, {x:800, y:600});
        }
        public function toTopCorner(currSpr:Sprite):void {
            TweenLite.to(currSpr, 3, {x:0, y:0});
        }

How to make the first one proccess and then the second? Thank you!

Upvotes: 0

Views: 40

Answers (1)

Gurtej Singh
Gurtej Singh

Reputation: 3234

You should use the 'onComplete' provided by TweenLite on your first animation. It requires a method name, and use the 'onCompleteParams' to send the parameters to the method call.

So, your code would look like this now:

   public function toBotCorner(currSpr:Sprite):void {
        TweenLite.to(currSpr, 3, {x:800, y:600, onComplete:toTopCorner, onCompleteParams:[currSpr]});
   }
   public function toTopCorner(currSpr:Sprite):void {
        TweenLite.to(currSpr, 3, {x:0, y:0});
   }

Note that the onCompleteParams: is an array as a method could have multiple parameters to be passed.

Here's what the docs says:

onComplete : Function - A function that should be called when the tween has completed

onCompleteParams : Array - An Array of parameters to pass the onComplete function.

Upvotes: 1

Related Questions