# Trouble with tweenlite used in for loop

**URL:** <https://forum.kirupa.com/t/trouble-with-tweenlite-used-in-for-loop/278603>\
**Category:** random\
**Created:** [January 2, 2009, 3:01pm UTC](https://forum.kirupa.com/t/trouble-with-tweenlite-used-in-for-loop/278603 "2009-01-02T15:01:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chief06](https://avatars.discourse-cdn.com/v4/letter/c/e19b73/32.png) [@Chief06](https://forum.kirupa.com/u/Chief06)\
**Post date:** [January 2, 2009, 3:01pm UTC](https://forum.kirupa.com/t/trouble-with-tweenlite-used-in-for-loop/278603/1 "2009-01-02T15:01:13Z")

</div>

I’m developing a board game in AS2, using tweenlite to move the players after a dice roll. Each player is a human character facing different directions in its timeline, and a walking animation of each character in that timeline. To keep the walking relatively smooth, I have the player movement set up in a FOR LOOP to iterate x times (the dice roll = moveCount) and walk from space to space, turning direction if the board direction changes.

The only challenge is when the dice rolls a number higher than 1, the player piece sort of “scoots” directly to that next space (kind of running in air), not stepping thru the tween the required number of times.

Here’s a simplified version of my code:

[AS]//This is part of the function that calls the movePlayer function, which contains the TweenLite.to

//step the number of spaces on this roll  
for (var i:Number = 1; i \<= moveCount; i++)  
{  
movePlayer(playerID, startNum, nextNum);  
startNum++;  
nextNum++;  
}\*/

function movePlayer(playerID:Number, startNum:Number, nextNum:Number):Void {

//move the current player, exec walk motion while tweening  
TweenLite.to (currentPlayer, 2,  
{  
\_x:(thePoint.x)-offsetX,  
\_y:(thePoint.y)-offsetY,  
delay:.25,  
onStart:doTheWalk,  
onStartParams:[currentPlayer, walkDir],  
onComplete:doTheRest,  
onCompleteParams:[currentPlayer, restDir]  
}  
);

}

//rotate player into exit position  
function doTheExit(thePlayer:MovieClip, exitDirection:String):Void  
{  
thePlayer.gotoAndPlay(exitDirection);  
}

//player walk animation  
function doTheWalk(thePlayer:MovieClip, walkDirection:String):Void  
{  
thePlayer.gotoAndPlay(walkDirection);  
}

//rotate player into rest position  
function doTheRest(thePlayer:MovieClip, restDirection:String):Void  
{  
thePlayer.gotoAndPlay(restDirection);  
}[/AS]

I’ve tried using the overwrite property to prevent the next tween from running before the current one finishes to no avail. I’ve also tried using a simple timing loop within the for…next code, that doesn’t work either.

Any ideas what I’m missing here? I’m pulling my hair out (and I don’t have too much of that left).
