# Random movement

**URL:** <https://forum.kirupa.com/t/random-movement/27478>\
**Category:** Uncategorized\
**Created:** [August 3, 2003, 12:41am UTC](https://forum.kirupa.com/t/random-movement/27478 "2003-08-03T00:41:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pez](https://avatars.discourse-cdn.com/v4/letter/p/5e9695/32.png) [@pez](https://forum.kirupa.com/u/pez)\
**Post date:** [August 3, 2003, 12:41am UTC](https://forum.kirupa.com/t/random-movement/27478/1 "2003-08-03T00:41:39Z")

</div>

I just did the tutorial on random movement for flash mx, and it says how to specify the width and height, but what if i want to specify an area in the middle of the page, not just the whole page?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 3, 2003, 1:14am UTC](https://forum.kirupa.com/t/random-movement/27478/2 "2003-08-03T01:14:15Z")

</div>

1. You could simply put those objects inside a MovieClip and move it to the appropriate position.

2. Replace the reset prototype with this code:  
[AS]// change these values  
var area = {xmin:40, xmax:100, ymin:40, ymax:100};  
MovieClip.prototype.reset = function() {  
var dist, norm;  
this.x = this.\_x;  
this.y = this.\_y;  
this.speed = Math.random()\*4+2;  
this.targx = area.xmin+Math.random()\*area.xmax-area.xmin;  
this.targy = area.ymin+Math.random()\*area.ymax-area.ymin;  
dist = getdistance(this.x, this.y, this.targx, this.targy);  
norm = this.speed/dist;  
this.diffx = (this.targx-this.x)\*norm;  
this.diffy = (this.targy-this.y)\*norm;  
};[/AS]
