# Restrict mouse follow?

**URL:** <https://forum.kirupa.com/t/restrict-mouse-follow/20599>\
**Category:** Uncategorized\
**Created:** [May 11, 2003, 12:54am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599 "2003-05-11T00:54:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![molotov](https://avatars.discourse-cdn.com/v4/letter/m/9f8e36/32.png) [@molotov](https://forum.kirupa.com/u/molotov)\
**Post date:** [May 11, 2003, 12:54am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/1 "2003-05-11T00:54:06Z")

</div>

i’m using flash mx.  
i’ve got a mask following the mouse and was wondering how i could restrict the code so the mask would only follow the mouse when it was in a certain portion of the scene.

basically i’ve got it following the mouse for a menu navigation and want to know how to not have the mask following the mouse when it moves outside of that menu area.

---

<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:** [May 11, 2003, 4:41am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/2 "2003-05-11T04:41:04Z")

</div>

just check the coordinates around the menu area and when the mouse is within those have it run the follow code

---

<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:** [May 11, 2003, 6:32am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/3 "2003-05-11T06:32:26Z")

</div>

yeah not sure how to do that, where do i tell it the coordinates, i am still a noob to flash

---

<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:** [May 11, 2003, 8:38am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/4 "2003-05-11T08:38:31Z")

</div>

try something like

```auto

onClipEvent(load) {
     follow = true;
}

onClipEvent (enterFrame) {
if (follow) {
// mousefollowcode
}
if (this._x > XMAX || this._x <XMIN ||this._y > YMAX || this._y < YMIN)
    follow = false;
else
    follow = true;
}

```

where XMAX etc are coordinates values to restrict the area

---

<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:** [May 11, 2003, 9:20am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/5 "2003-05-11T09:20:19Z")

</div>

thanks sweepa

---

<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:** [May 11, 2003, 9:37am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/6 "2003-05-11T09:37:28Z")

</div>

doesn’t work

---

<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:** [May 11, 2003, 10:36am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/7 "2003-05-11T10:36:12Z")

</div>

did u cut and paste the code in? and if so, did u change anything? if not, therein lies your problem, you have to set XMAX to a value, same for the Y.

---

<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:** [May 11, 2003, 11:00am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/8 "2003-05-11T11:00:36Z")

</div>

yes i did that, i’m not that much of a noob.

in case it matters here’s my mouse follow code -\>  
onClipEvent (load) {  
\_x = 0;  
speed = 5;  
}  
onClipEvent (enterFrame) {  
endX = \_root.\_xmouse;  
\_x += (endX-\_x)/speed;  
}

---

<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:** [May 11, 2003, 4:07pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/9 "2003-05-11T16:07:22Z")

</div>

Ok im going to assume you intend to follow only along the x-axis since thats what your code is doing. I am also assuming you just want to limit the mask and not the mouse pointer itself (if so just remove the \_x \> XMAX and \_x \< XMIN part).

```auto

onClipEvent (load) {
	_x = 300;
 XMIN = 100;
 XMAX = 500;
	speed = 5;
}
onClipEvent (enterFrame) {
	if (_root._xmouse < XMAX && _x < XMAX) 
		outOfRegion = true;
	else if (_root._xmouse > XMIN && _x > XMIN) 
		outOfRegion = true;
	else 
		outOfRegion = false;
	if (!outOfRegion) {
		endX = _root._xmouse;
		_x += (endX-_x)/speed;
	}
}

```

tested it and it seems to work, hope this is what you want

---

<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:** [May 11, 2003, 4:47pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/10 "2003-05-11T16:47:59Z")

</div>

making things a bit easier… 😉

```auto
onClipEvent (enterFrame) {
	if (_root._xmouse>XMIN && _root._xmouse<XMAX) {
		endX = _root._xmouse;
	}
	this._x += (endX-this._x)/speed;
}

```

---

<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:** [May 11, 2003, 6:34pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/11 "2003-05-11T18:34:39Z")

</div>

didn’t work for me. i’m posting my fla if anyone wants to look at and see what i’m doing wrong. when looking at it keep in mind i don’t want the mask to move when below the menu title bar.

[page01.fla](http://molotovfx.com/page01.fla)

---

<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:** [May 11, 2003, 9:47pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/12 "2003-05-11T21:47:26Z")

</div>

here is the working version… i commented it so i hope it helps you… since you said you are new to AS i explained how and why i did what i did to the code (the one line i added heh) and the line is in the easing code for the mask

the file was too big to upload here so i put it on a site…

[http://www.freewebs.com/scottgilmore/page01.zip](http://www.freewebs.com/scottgilmore/page01.zip)

---

<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:** [May 11, 2003, 9:48pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/13 "2003-05-11T21:48:11Z")

</div>

the link doesnt seem to work when i tried it to test it so just copy and paste it into the address bar if you need to

---

<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:** [May 11, 2003, 10:25pm UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/14 "2003-05-11T22:25:06Z")

</div>

great stuff Scootman!

thanks for comments too. made it look so easy, must be nice to know what your doing.

---

<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:** [May 12, 2003, 12:40am UTC](https://forum.kirupa.com/t/restrict-mouse-follow/20599/15 "2003-05-12T00:40:47Z")

</div>

glad i could help
