PDA

View Full Version : Restrict mouse follow?



molotov
May 10th, 2003, 08:54 PM
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.

Scootman
May 11th, 2003, 12:41 AM
just check the coordinates around the menu area and when the mouse is within those have it run the follow code

molotov
May 11th, 2003, 02:32 AM
yeah not sure how to do that, where do i tell it the coordinates, i am still a noob to flash

sweepah
May 11th, 2003, 04:38 AM
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

molotov
May 11th, 2003, 05:20 AM
thanks sweepa

molotov
May 11th, 2003, 05:37 AM
doesn't work

dizknee
May 11th, 2003, 06:36 AM
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.

molotov
May 11th, 2003, 07:00 AM
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;
}

sweepah
May 11th, 2003, 12:07 PM
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

kode
May 11th, 2003, 12:47 PM
making things a bit easier... ;)

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

molotov
May 11th, 2003, 02:34 PM
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)

Scootman
May 11th, 2003, 05:47 PM
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

Scootman
May 11th, 2003, 05:48 PM
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

molotov
May 11th, 2003, 06:25 PM
great stuff Scootman!

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

Scootman
May 11th, 2003, 08:40 PM
glad i could help