# Mouse follow in a contained area

**URL:** <https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751>\
**Category:** Uncategorized\
**Created:** [May 30, 2002, 3:47pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751 "2002-05-30T15:47:05Z")\
**Posts on this page:** 6\
**Page:** 1

<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 30, 2002, 3:47pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/1 "2002-05-30T15:47:05Z")

</div>

I’ve managed to figure out the action scripting for a mouse follow along a Y axis. I want to limit the follow to just a certain contained area on the page. What scripting would I use for that? Thanks

kristinu

---

<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 30, 2002, 3:48pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/2 "2002-05-30T15:48:16Z")

</div>

add an if statement to limit the area. post if you need more indepth answers.

---

<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 30, 2002, 3:52pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/3 "2002-05-30T15:52:26Z")

</div>

yeah, i’m a little slow on the uptake…

I downloaded a certain mouse follow script from virtual fx:  
[virtual-fx.net/vfx/tutori…020109.php](http://virtual-fx.net/vfx/tutorial/tutorial6_186_20020109.php)  
…

The action scripting that goes along with it is:

thisY = getProperty("/drg1", \_y);  
spY = getProperty("/spin1", \_y);  
difY = thisY-spY;  
yStp = difY/10;  
setProperty("/spin1", \_y, Number(spY)+Number(yStp));  
…

Where in this party of fun would I place the if? Thanks for the quick reply 🙂

kristinu

---

<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 30, 2002, 4:02pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/4 "2002-05-30T16:02:22Z")

</div>

Ok, well I’m about to throw a grenade into your party. That tutorial was made in Flash 4 and it used depreciated code (old code) I fixed the code so it is updated:

onClipEvent(load){  
&nbsp &nbsp &nbsp &nbsp friction = 8  
}  
onClipEvent(enterFrame){  
&nbsp &nbsp &nbsp &nbsp nXdiff = \_root.\_xmouse - \_x  
&nbsp &nbsp &nbsp &nbsp nYdiff = \_root.\_ymouse - \_y  
&nbsp &nbsp &nbsp &nbsp \_x += nXdiff/friction  
&nbsp &nbsp &nbsp &nbsp \_y += nYdiff/friction  
}

this code would go right on the MovieClip. Now with the restriction it would look like:

onClipEvent (load) {  
&nbsp &nbsp &nbsp &nbsp friction = 8;  
}  
onClipEvent (enterFrame) {  
&nbsp &nbsp &nbsp &nbsp nXdiff = \_root.\_xmouse - \_x;  
&nbsp &nbsp &nbsp &nbsp nYdiff = \_root.\_ymouse - \_y;  
&nbsp &nbsp &nbsp &nbsp if (\_root.\_xmouse \>= 50 && \_root.\_xmouse \<= 300) {  
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_x += nXdiff / friction;  
&nbsp &nbsp &nbsp &nbsp }  
&nbsp &nbsp &nbsp &nbsp if (\_root.\_ymouse \>= 50 && \_root.\_ymouse \<= 300) {  
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp \_y += nYdiff / friction;  
&nbsp &nbsp &nbsp &nbsp }  
}

if you have any specific questions, ask away…

---

<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 30, 2002, 4:17pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/5 "2002-05-30T16:17:09Z")

</div>

Everything worked out well. Thanks for helping me out with that. I was pretty sure that the code I was using was older than sin. Thanks again

kristinu

---

<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 30, 2002, 4:28pm UTC](https://forum.kirupa.com/t/mouse-follow-in-a-contained-area/1751/6 "2002-05-30T16:28:52Z")

</div>

no problem. post again if ya ever need anything.
