Jump to content
Search Community

How do you wait for a tween inside a for loop to complete?

jdfinch3 test
Moderator Tag

Recommended Posts

I'm drawing a large shape using an array of points in a for loop and tweenlite as found at http://www.flashperfection.com/tutorials/Animated-line-drawing-using-TweenLite-in-AS3-22013.html

for(var i:uint = 0; i < pointsArray.length; i++){
TweenLite.to(dot2, .05, {x:pointsArray[i].x,
  y:pointsArray[i].y,
  delay:i*.05,
  overwrite:false,
 onUpdate:updateHandler});
}
function updateHandler():void{
lineAnim.graphics.lineTo(dot2.x, dot2.y);
lineAnim.graphics.moveTo(dot2.x, dot2.y);
}

 

I would like the animation to complete before continuing, but I'm unable to find a way to be notified when the full animation is complete.  onComplete does not work as it triggers on the first set of coords.  I also tried triggering when

i == pointsArray.length

but the loop finishes multiple seconds before the animation completes.  I would like to avoid using a timer.

Link to comment
Share on other sites

For something like this I would recommend that you use your loop to generate tweens that get placed in a timeline. That will make them all play in direct succession.

 

import com.greensock.*;
import com.greensock.easing.*;


var points:Array = [{x:100, y:100}, {x:200, y:0}, {x:300, y:100}];


var tl:TimelineLite = new TimelineLite();


for (var i:int = 0; i < points.length; i++){
  tl.to(mc, 0.5, {x:points[i].x, y:points[i].y}) 
}

Just create an FLA that has a MovieClip with instance name mc to test.

 

Check out the TimelineLite docs for more info: http://greensock.com/asdocs/com/greensock/TimelineLite.html#to()

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...