PDA

View Full Version : How to pause and play the random action?


ROYOW
10-14-2005, 11:19 PM
Can someone help me to find the solution to pause and then play the random action? The following is the code I attached to a movie clip. Thank you for your help in advance!!!:confused:


onClipEvent (load) {
//data you may want to change
width = 14;
height = 14;
speed = Math.round(Math.random()*0.5)+0.3;
//initial positions
x = Math.random()*width;
y = Math.random()*height;
this._x = x;
this._y = y;
x_new = Math.random()*width;
y_new = Math.random()*height;
}
onClipEvent (enterFrame) {
//x movement
if (x_new>this._x) {
sign_x = 1;
} else {
sign_x = -1;
}
dx = Math.abs(x_new-this._x);
if ((dx>speed) || (dx<-speed)) {
this._x += sign_x*speed;
} else {
x_new = Math.random()*width;
}
//y movement
if (y_new>this._y) {
sign_y = 1;
} else {
sign_y = -1;
}
dy = Math.abs(y_new-this._y);
if ((dy>speed) || (dy<-speed)) {
this._y += sign_y*speed;
} else {
y_new = Math.random()*height;
}
}