# Following the mouse... a limit?

**URL:** <https://forum.kirupa.com/t/following-the-mouse-a-limit/59285>\
**Category:** flash\
**Created:** [July 29, 2004, 10:32pm UTC](https://forum.kirupa.com/t/following-the-mouse-a-limit/59285 "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/59285/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:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 30, 2004, 1:51pm UTC](https://forum.kirupa.com/t/following-the-mouse-a-limit/59285/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!
