# Following the mouse... a limit?

**URL:** <https://forum.kirupa.com/t/following-the-mouse-a-limit/117745>\
**Category:** Uncategorized\
**Created:** [July 29, 2004, 10:32pm UTC](https://forum.kirupa.com/t/following-the-mouse-a-limit/117745 "2004-07-29T22:32:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![l2edsand](https://avatars.discourse-cdn.com/v4/letter/l/ecd19e/32.png) [@l2edsand](https://forum.kirupa.com/u/l2edsand)\
**Post date:** [July 29, 2004, 10:32pm UTC](https://forum.kirupa.com/t/following-the-mouse-a-limit/117745/1 "2004-07-29T22:32:21Z")

</div>

Hello,

```
I have a mask that follows my mouse around the screen on the x axis only... What I want is to only allow the "follower" to go to a certain point on the right and the left... in other words, I don't want the follower to be able to go off/out of the stage.

Here's my code:

```

follow.onEnterFrame = function() {

```
var xMouse = _root._xmouse;

```

if(Math.abs(xMouse - this.\_x) \< 1) {

```
this._x = xMouse;

} else {

this._x -= (this._x-xMouse) / 6;

```

}  
}

---

<div class="post-metadata">

**Author:** ![Mediamonkey](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Mediamonkey](https://forum.kirupa.com/u/Mediamonkey)\
**Post date:** [July 30, 2004, 1:51pm UTC](https://forum.kirupa.com/t/following-the-mouse-a-limit/117745/2 "2004-07-30T13:51:13Z")

</div>

```auto
limitleft = 0;
limitright = Stage.width;
halfway = (limitleft+limitright)/2;
 
follow.onEnterFrame = function() {
    xMouse = ... // define your xMouse beforehand
    if (this._x > halfway) {
        this._x = Math.min(limitright, xMouse);
    } else {
        this._x = Math.max(limitleft, xMouse);
    }
}

```

This way you separate the movement from the rendering (placing the mc according to the calculated position). good luck!
