Following the mouse... a limit?

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;

}
}

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!