# Putting a stop to random motion: help!

**URL:** <https://forum.kirupa.com/t/putting-a-stop-to-random-motion-help/169836>\
**Category:** flash\
**Created:** [November 20, 2005, 2:39am UTC](https://forum.kirupa.com/t/putting-a-stop-to-random-motion-help/169836 "2005-11-20T02:39:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PopRocks](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@PopRocks](https://forum.kirupa.com/u/PopRocks)\
**Post date:** [November 20, 2005, 2:39am UTC](https://forum.kirupa.com/t/putting-a-stop-to-random-motion-help/169836/1 "2005-11-20T02:39:47Z")

</div>

hi there,

i’m working on my final project for a digital media class, using flash. i have some (movie clip) objects that i’ve programmed for random movements, but i’d like them to stop when the user clicks on them. oddly enough, i can’t find code for this anywhere.

i’m not too flash savvy, but i love to learn new things! code is great, and an explanation would be even more amazing. but i’ll take what i can get. here’s what i have so far:

acceleration = 10  
newpos = function () {  
ranx = Math.round((Math.random ()\*375));  
rany = Math.round ((Math.random ()\*400));  
}  
newpos();  
this.onEnterFrame = function() {  
this.\_x += ((ranx-this.\_x)/acceleration);  
this.\_y += ((rany-this.\_y)/acceleration);  
if (Math.round(this.\_x) == ranx || Math.round(this.\_y) == rany) {  
newpos();  
}  
};

extra info that might be helpful: i’ve placed this code on the first frame of the object’s movie clip timeline, and then placed the movie clip on the first frame of my main timeline.

thank you!
