# how do I randomly multiply movieclip-function

on
I have a small movieclip that I move from one place to another with the tween class. But I want the movieclip-function - see code below -  to multiply into a flow, that follow each other constantly. Like bloodcells. Preferably randomnly, but still along the same line.

``````import mx.transitions.Tween;
import mx.transitions.easing.Regular;
attachMovie("bloodcell","bloodcell_mc",10);
moveBlood = function(){
new mx.transitions.Tween(bloodcell_mc, "_x", Regular.easeIn, 30, 500, 1, true);
new mx.transitions.Tween(bloodcell_mc, "_y", Regular.easeIn, 30, 200, 1, true);
}
``````
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2008

Commented:
here is a sample code, which may lead you to get the required reason..
just replace your existing code with the following:

``````import mx.transitions.Tween;
import mx.transitions.easing.Regular;

var total = 20;
for (var i = 0; i<total; i++) {
var mc = this.attachMovie("bloodcell", "bloodcell_mc"+i, i);
mc._x = 30*Math.random();
mc._y = 30*Math.random();
var duration = 2*Math.random();
var x = 500+mc._x;
var y = 200+mc._y;
moveBloodCell(mc,x,y,duration);
}

function moveBloodCell(mc, x, y, duration) {
new mx.transitions.Tween(mc, "_x", Regular.easeIn, mc._x, x, duration, true);
new mx.transitions.Tween(mc, "_y", Regular.easeIn, mc._y, y, duration, true);
}
``````

Commented:
Thanks, excellent.
But is there a way to make the flow continue endlessly. So it doesnt look as if it ends before it restarts.
Top Expert 2008
Commented:
here is the updated code for endless animation:
``````import mx.transitions.Tween;
import mx.transitions.easing.Regular;

var total = 20;
for (var i = 0; i<total; i++) {
var mc = this.attachMovie("bloodcell", "bloodcell_mc"+i, i);
var range = 100;
mc._x = range*Math.random();
mc._y = range*Math.random();
var duration = 0.5+1.5*Math.random();
var finalX = 500+mc._x;
var finalY = 200+mc._y;
moveBloodCell(mc,mc._x,mc._y,finalX,finalY,duration);
}

function moveBloodCell(mc, iX,iY,fX,fY, duration) {
var _this = this;
new mx.transitions.Tween(mc, "_x", Regular.easeIn, iX,fX, duration, true);
var tw = new mx.transitions.Tween(mc, "_y", Regular.easeIn, iY,fY, duration, true);
tw.onMotionFinished = function(){
_this.moveBloodCell(mc, iX,iY,fX,fY, duration);
}
}
``````

Commented:
Thank you very much, simply perfect.

Do more with