# Random motion interesting problem

**URL:** https://forum.kirupa.com/t/random-motion-interesting-problem/68605
**Category:** flash
**Created:** [October 27, 2004, 8:51am UTC](https://forum.kirupa.com/t/random-motion-interesting-problem/68605 "2004-10-27T08:51:30Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![njdboy](https://avatars.discourse-cdn.com/v4/letter/n/b19c9b/32.png) [@njdboy](https://forum.kirupa.com/u/njdboy)
#### Post date: [October 27, 2004, 8:51am UTC](https://forum.kirupa.com/t/random-motion-interesting-problem/68605/1 "2004-10-27T08:51:30Z")

</div>

I followed the random motion tutorial:  
[http://www.kirupa.com/developer/actionscript/random\_motion.htm](http://www.kirupa.com/developer/actionscript/random_motion.htm)

How do I make this play for 3-4 seconds and then delete the movieclip all together?

This is my mc code:

```auto
onClipEvent (load) { 
//data you may want to change 
width = 500; 
height = 350; 
speed = Math.round(Math.random()*7)+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; 
} 
} 

```

And this is the code on the frame:

```auto
i = 0; 
while (i<15) { 
//duplicateMovieClip(dot, "dot"+i, i); 
dot.duplicateMovieClip("dot"+i, i); 
i++; 
} 

```
