# Need help about random motion

**URL:** <https://forum.kirupa.com/t/need-help-about-random-motion/82059>\
**Category:** Uncategorized\
**Created:** [March 7, 2005, 3:26pm UTC](https://forum.kirupa.com/t/need-help-about-random-motion/82059 "2005-03-07T15:26:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![delamyra](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@delamyra](https://forum.kirupa.com/u/delamyra)\
**Post date:** [March 7, 2005, 3:26pm UTC](https://forum.kirupa.com/t/need-help-about-random-motion/82059/1 "2005-03-07T15:26:14Z")

</div>

i’m very2 new with flash.

so here’s the script from [http://www.kirupa.com/developer/actionscript/random\_motion.htm](http://www.kirupa.com/developer/actionscript/random_motion.htm)

i’ve changed it a little bit to fit my movie dimension

```
onClipEvent (load) {

//data you may want to change
width = 1050;
height = 300;
speed = Math.round(Math.random()*80)+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&gt;this._x) {

sign_x = 1;
} else {
sign_x = -1;

}
dx = Math.abs(x_new-this._x);
if ((dx&gt;speed) || (dx&lt;-speed)) {

this._x += sign_x*speed;
} else {
x_new = Math.random()*width;

}
//y movement
if (y_new&gt;this._y) {

sign_y = 1;
} else {
sign_y = -1;

}
dy = Math.abs(y_new-this._y);
if ((dy&gt;speed) || (dy&lt;-speed)) {

this._y += sign_y*speed;
} else {
y_new = Math.random()*height;

}

}

```

but the thing is. i want it to move only around the region  
width = from 850px tilll 1050px  
and  
height = from 100px to 300px

where do i change?

thanks in advance.
