Restricting mouse follow

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.

Try hitTest, something like:

myStageMC.onMouseMove = function() {
    if (this.hitTest(_root._xmouse, _root._ymouse, false)) {
        // do something
    }
};
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]

=)

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

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

I´m the of easy answers to easy questions!

:stuck_out_tongue:

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

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

Good code btw.

=)

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?

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 <:}

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!

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

	}
}
{

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

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


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…

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