# Random generator interaction question

**URL:** <https://forum.kirupa.com/t/random-generator-interaction-question/77162>\
**Category:** Uncategorized\
**Created:** [January 25, 2005, 4:58am UTC](https://forum.kirupa.com/t/random-generator-interaction-question/77162 "2005-01-25T04:58:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mavrik7384](https://avatars.discourse-cdn.com/v4/letter/m/b2d939/32.png) [@mavrik7384](https://forum.kirupa.com/u/mavrik7384)\
**Post date:** [January 25, 2005, 4:58am UTC](https://forum.kirupa.com/t/random-generator-interaction-question/77162/1 "2005-01-25T04:58:50Z")

</div>

I have the following code for a movie clip to generate random squares and move them around.

onClipEvent (load) {  
//data you may want to change  
width = 600;  
height = 400;  
speed = Math.round(Math.random()\*2)+1;  
//initial positions  
x = this.\_x=Math.random()\*width;  
y = this.\_y=Math.random()\*height;  
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;  
}  
}

this code is on a square which was converted to a movie clip  
the timeline frame has this code:

i = 0;  
while (i\<25) {  
//duplicateMovieClip(dot, “dot”+i, i);  
dot.duplicateMovieClip(“dot”+i, i);  
i++;  
}

I would like all the squares to stop moving and fall off the bottom of the window when the user clicks anywhere in the feild. ideas?
