Restrict mouse follow?

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.

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

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

try something like


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

thanks sweepa

doesn’t work

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.

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

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).


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

making things a bit easier… :wink:

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

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

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

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

great stuff Scootman!

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

glad i could help