PDA

View Full Version : [FMX]Function random movement



dboers
April 23rd, 2004, 04:14 AM
I have the following clipEvent on a movieclip called square:

onClipEvent (enterFrame) {
xmove = (xpos-this._x)/5;
this._x += xmove;
}

And the following framecode in the same keyframe as square:

_root.square.xpos = Math.round(Math.random()*550);

Now I want to use this information in a function so I can control more than just one clip.

How should this function look like?

dboers
April 24th, 2004, 02:43 AM
I will try to explain myself a little better. I have four clips on the stage(ball1, ball2, ball3, ball4). Each clip has the following clipEvent attached:
onClipEvent (enterFrame) {
xmove = (xpos-this._x)/5;
this._x += xmove;
}
I want the clips to randomly move on the x axis, so now I have the following script attached to the first frame:

_root.ball1.xpos = Math.round(Math.random()*550);
_root.ball2.xpos = Math.round(Math.random()*550);
_root.ball3.xpos = Math.round(Math.random()*550);
_root.ball4.xpos = Math.round(Math.random()*550);

So for every clip I have declared a Math.random. How can I accomplish the same result with a fuction, so that I don't have to set the Math.random for every clip seperate?