# Trouble Stopping Random Movement

**URL:** <https://forum.kirupa.com/t/trouble-stopping-random-movement/257075>\
**Category:** flash\
**Created:** [April 10, 2008, 12:26am UTC](https://forum.kirupa.com/t/trouble-stopping-random-movement/257075 "2008-04-10T00:26:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![designcompound](https://avatars.discourse-cdn.com/v4/letter/d/b782af/32.png) [@designcompound](https://forum.kirupa.com/u/designcompound)\
**Post date:** [April 10, 2008, 12:26am UTC](https://forum.kirupa.com/t/trouble-stopping-random-movement/257075/1 "2008-04-10T00:26:23Z")

</div>

Hello -

I am having trouble stopping my random movement code. What I would like to do is make the random movement stop wherever the mc’s are and slide to a specific location using “myClickedBtnFunction()”. Please help!

This is on each of the MC’s that I have calling the code from the main timeline.

_[COLOR=red]onClipEvent(enterframe) {  
move();  
}[/COLOR]_  
_[COLOR=red]on (rollOver) {  
this.\_parent.btn = “link1”  
this.\_parent.myRolloverBtnFunction()  
}  
on (rollOut) {  
this.\_parent.btn = “link1”  
this.\_parent.myRolloutBtnFunction()  
}  
on (release) {  
this.\_parent.btn = “link1”  
this.\_parent.myClickedBtnFunction ()  
}[/COLOR]_  
_[COLOR=#ff0000][/COLOR]_  
[COLOR=black]On the main timeline I have the following code  
[/COLOR]  
[COLOR=red]_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() {  
width = 615;  
height = 514;  
var dist, norm;  
this.x = this.\_x;  
this.y = this.\_y;  
this.speed = .5;  
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\>00000001) {  
this.reset();  
this.t = 1;  
}  
}  
this.\_x = this.x;  
this.\_y = this.y;  
};_[/COLOR]  
_[COLOR=#ff0000][/COLOR]_  
_[COLOR=#ff0000][/COLOR]_
