3 Replies Latest reply on Feb 22, 2011 5:29 AM by Ned Murphy

# Flash tween class, more than one tween for a movieclip?

EDIT:

```for (i=0; i<humans; i++) {
ranDistX = Math.floor(Math.random()*(20-(-20+1)))+-20;
ranDistY = Math.floor(Math.random()*(20-(-20+1)))+-20;
var humansMoving = new Tween(_root["human"+i], "_x", Linear, _root["human"+i]._x, _root["human"+i]._x+ranDistX, 2, true);
var humansMoving = new Tween(_root["human"+i], "_y", Linear, _root["human"+i]._y, _root["human"+i]._y+ranDistY, 2, true);

humansMoving.onMotionFinished = function() {
humansMoving.start();
ranDistX = Math.floor(Math.random()*(20-(-20+1)))+-20;
ranDistY = Math.floor(Math.random()*(20-(-20+1)))+-20;
};
}

```

The tween works only once. I need it so when the tween is finished, it does the same tween(with a different random number(different position)), however after the first two tweens (x and y) have finished the movieclips just sit there. Anyone know how to do this?

• ###### 1. Re: Flash tween class, more than one tween for a movieclip?

There are a couple things wrong in that code.  You can't have two variables named the same and redefining the random values won't change what's been assigned to the tweens.  You need to keep redefining the tweens.  Here's a link to a working sample of the code I offered you yesterday.

.

http://www.nedwebs.com/Flash/AS2_Random_Motion.fla

• ###### 2. Re: Flash tween class, more than one tween for a movieclip?

ah wow I eventually go it implimented in and it works! Thank you very much and sorry for not doing it yesterday! The movement is perfect, thanks! Now all I need is a way to stop the tweens because they sometimes get interupted and need to move in a different direction but cant because they are still in a tween.

Before I used this:

_root["human"+i].stopTween("_x","_y");

But now it doesnt work.. hmm I will persevere some more

again thanks!

• ###### 3. Re: Flash tween class, more than one tween for a movieclip?

You're welcome