Mouse Follow Snap To Position if

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:

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