# Mouse Follow Snap To Position if

**URL:** <https://forum.kirupa.com/t/mouse-follow-snap-to-position-if/285359>\
**Category:** flash\
**Created:** [March 30, 2009, 10:23pm UTC](https://forum.kirupa.com/t/mouse-follow-snap-to-position-if/285359 "2009-03-30T22:23:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![student07](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@student07](https://forum.kirupa.com/u/student07)\
**Post date:** [March 30, 2009, 10:23pm UTC](https://forum.kirupa.com/t/mouse-follow-snap-to-position-if/285359/1 "2009-03-30T22:23:59Z")

</div>

Hello,

How would you force a mouse follow movieclip to snap to a x y position if it reaches x y boudaries or perhaps if a button is released the movie clip snaps to a x y position? Of course if the mouse returns to x y boundaries I’d like for the movie clip to follow again.

Right now this is the code I’m using to make the movieclip follow the mouse within x y boundaries:

```auto
onClipEvent (load) {
    _x = 0;
    _y = 0;
    speed = 5;
}
onClipEvent (enterFrame) {
    endX = _root._xmouse;
    endY = _root._ymouse;
    _x += (endX-_x)/speed;
    _y += (endY-_y)/speed;
    if(_root._xmouse < 250 && _root._xmouse > 150){}
    if ( this._x >=908){this._x=908;}
 if ( this._x<=300){this._x=300;}
}

```

thanks
