# Setting a limit to a moving object?

**URL:** <https://forum.kirupa.com/t/setting-a-limit-to-a-moving-object/88323>\
**Category:** flash\
**Created:** [April 28, 2005, 12:20pm UTC](https://forum.kirupa.com/t/setting-a-limit-to-a-moving-object/88323 "2005-04-28T12:20:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scyth](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@Scyth](https://forum.kirupa.com/u/Scyth)\
**Post date:** [April 28, 2005, 12:20pm UTC](https://forum.kirupa.com/t/setting-a-limit-to-a-moving-object/88323/1 "2005-04-28T12:20:08Z")

</div>

I have a wide rectangular MC that goes offscreen (verrrrrry wide) and i have this code on it:

onClipEvent (load)  
{  
xcenter=150;  
speed=1/10;  
}  
onClipEvent (enterFrame)  
{  
var distance=\_root.\_xmouse-xcenter;  
\_x+=(distance\*speed);  
}

(looks familiar? Its part of the code for the infinite menu).

Now I need the MC to stop moving when it reaches either end. I’ve tried If statements but that seems to halt the whole process altogether. I know Im missing something but i, for the life of me, cant seem to see it.

Any help on this, folks?
