# Restricting mouse follow

**URL:** <https://forum.kirupa.com/t/restricting-mouse-follow/9279>\
**Category:** Uncategorized\
**Created:** [December 9, 2002, 12:50am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279 "2002-12-09T00:50:38Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![buddylee](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@buddylee](https://forum.kirupa.com/u/buddylee)\
**Post date:** [December 9, 2002, 12:50am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/1 "2002-12-09T00:50:38Z")

</div>

Ok, how do I make it so that the an object only follows your mouse between certain points? I have a square with the code  
startDrag("", true). Then I put an if then statement saying…

if(this.\_x \<=200){  
startDrag("", false)  
}

I figured this would do the job pretty easily, but it does not. Any ideas? Thanx

I dont know why there is a smily face up there.

---

<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:** [December 9, 2002, 4:19pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/2 "2002-12-09T16:19:28Z")

</div>

Try hitTest, something like:

```php
myStageMC.onMouseMove = function() {
    if (this.hitTest(_root._xmouse, _root._ymouse, false)) {
        // do something
    }
};

```

---

<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:** [December 9, 2002, 4:26pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/3 "2002-12-09T16:26:59Z")

</div>

```php
on (press) {
    startDrag("", false, 0, 0, 400, 400 );
}
on (release) {
    stopDrag();
}

```

the numbers serve to restrain the movement in a square of:  
\*\*left = \*\*0px  
\*\*top = \*\*0px  
\*\*right = \*\*400px  
\*\*botton = \*\*400px

you can edit them.

[EDIT]remove the space after the last 400 to work on flash, I have to place the space there just to shoe right in this forum.[/EDIT]

=)

---

<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:** [December 9, 2002, 4:28pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/4 "2002-12-09T16:28:46Z")

</div>

Another easier option by guig0, Though hitTest is more powerful.

---

<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:** [December 9, 2002, 4:31pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/5 "2002-12-09T16:31:50Z")

</div>

> \*Originally posted by h88 \*  
> \*\*Another easier option by guig0, Though hitTest is more powerful. \*\*

I´m the of easy answers to easy questions!

😛

---

<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:** [December 10, 2002, 6:41pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/6 "2002-12-10T18:41:17Z")

</div>

Ok, we are gonna have to change things up a little. We are gonna use the same idea, but try to make it run more smoother. This is what I need you guys to help me with.

I am typing this at school, so I dont really remember all the proper names for the coding…

onClipEvent(enterFrame){  
if(this.\_xmouse \>300 && \<600){  
startDrag("", true)  
else  
startDrag("", false)  
}  
if(this.\_ymouse \>200 && \<400){  
startDrag("", true)  
else  
startDrag("", false)  
}  
}

Would that work? I cant try it b/c I am at school, but maybe one of you fellas can figure this out. If that does not work, will you please see if you can get me pointed in the right direction? Also, I do not understand how hitTest works, so if you could explain that also I would appreciate it.  
Thanks

---

<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:** [December 10, 2002, 6:57pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/7 "2002-12-10T18:57:02Z")

</div>

I think this should work too, later I will try that.

Good code btw.

=)

---

<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:** [December 11, 2002, 1:24am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/8 "2002-12-11T01:24:43Z")

</div>

Ok, this code is giving me some problems…

Scene=Scene 1, Layer=Pictures, Frame=1: Line 3: Operator ‘&&’ must be followed by an operand  
if(this.\_xmouse \>300 and \<600{

Any idea what an operand is?

---

<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:** [December 11, 2002, 8:29am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/9 "2002-12-11T08:29:57Z")

</div>

Yeah… It should be like this man:

if( this.\_xmouse \>300 and this.x\_mouse \<600 )  
blah blah blah

You gotta copy over the entire object : this.x\_mouse for it…

Peace Out,  
Marz \<:}

---

<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:** [December 12, 2002, 1:05am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/10 "2002-12-12T01:05:43Z")

</div>

can someone make a MC of a square or somthing, and see if they can get this code to work. I just want the square to follow the mouse as long as the mouse is bettween x coordinates of 300 and 600, and y coordinates of 200 and 400. This is driving me insane!

```php
onClipEvent (enterFrame) {
	if (this._xmouse>=300 && this._xmouse<=600) {
		startDrag("", true);
	} else {
		stopDrag();
	}
	if (this._ymouse>=200 && this._ymouse<=400) {
		startDrag("", true);
	} else {
		stopDrag();

	}
}
{

```

---

<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:** [December 12, 2002, 1:25am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/11 "2002-12-12T01:25:06Z")

</div>

you have to check the “DISABLE SMILIES IN THIS POST” checkbox it will get rid of those things…

---

<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:** [December 12, 2002, 5:51am UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/12 "2002-12-12T05:51:19Z")

</div>

Allright here… Check this code out man… I think this would suit your whole object theory and everything…

```php

if (_root._xmouse>=300)
{
     flag = true;
}
if (_root._xmouse<=600)
{
     flag = true;
}
if (_root._ymouse>=200) 
{
     flag = true;
}
if(_root._ymouse<=400)
{
     flag = true;
}
if(flag == true)
{
     _root.mcbox._x = _root._xmouse;
     _root.mcbox._y = _root._ymouse;
     flag = false;
}

```

Try this line of code out… It should work I think… I might have gotten the \_root.\_xmouse theories wrong but I think that is the way to do them…

Good Luck  
Marz \<:}

PS : Didn’t get a chance to try this out though… Might be mistaken in a coupe of parts but the genralization should prove to work out just fine…

---

<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:** [December 12, 2002, 9:04pm UTC](https://forum.kirupa.com/t/restricting-mouse-follow/9279/13 "2002-12-12T21:04:36Z")

</div>

This does not work for me! This is really starting to piss me off. Why wont any of these options work?
