# AS2 Flash CS3 Trying to bound a randomly moving MC. Help!

**URL:** <https://forum.kirupa.com/t/as2-flash-cs3-trying-to-bound-a-randomly-moving-mc-help/308587>\
**Category:** Uncategorized\
**Created:** [April 26, 2010, 3:33pm UTC](https://forum.kirupa.com/t/as2-flash-cs3-trying-to-bound-a-randomly-moving-mc-help/308587 "2010-04-26T15:33:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MattSepeta](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@MattSepeta](https://forum.kirupa.com/u/MattSepeta)\
**Post date:** [April 26, 2010, 3:33pm UTC](https://forum.kirupa.com/t/as2-flash-cs3-trying-to-bound-a-randomly-moving-mc-help/308587/1 "2010-04-26T15:33:49Z")

</div>

-Warning! Noob-

I am creating a banner with a “moving target”, but the target keeps moving under the copy text of the banner, making it illegible.

here is my random movement code (Swiped from kirupa if I recall :D) :

//special thanks to Suprabeener for the code  
function getdistance(x, y, x1, y1) {  
var run, rise;  
run = x1-x;  
rise = y1-y;  
return (\_root.hyp(run, rise));  
}  
function hyp(a, b) {  
return (Math.sqrt(a_a+b_b));  
}  
MovieClip.prototype.reset = function() {  
//specify the width and height of the movie  
width = 300;  
height = 180;  
//-------------------  
var dist, norm;  
this.x = this.\_x;  
this.y = this.\_y;  
this.speed = Math.random()\*25+25;  
this.targx = Math.random()\*width;  
this.targy = Math.random()\*height;  
dist = \_root.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;  
};  
MovieClip.prototype.move = function() {  
if (\_root.getdistance(this.x, this.y, this.targx, this.targy)\>this.speed) {  
this.x += this.diffx;  
this.y += this.diffy;  
} else {  
this.x = this.targx;  
this.y = this.targy;  
if (!this.t) {  
this.t = getTimer();  
}  
if (getTimer()-this.t\>250) {  
this.reset();  
this.t = 0;  
}  
}  
this.\_x = this.x;  
this.\_y = this.y;  
};

I have tried modifying the " width = 300;  
height = 180;" line, but it does not seem to be changing much, if anything.

I am trying to bound the random movement to the bottom 180 pixels of the composition.

Any pointers or resources would be great, thanks!!!
