-
Changing behavior based on Y, X coordinates over a Movie Clip with onMouseMove
Hello,
I was thinking that it will be an easy task but something is not right. Here is what I am trying to
do. I want to be able to run a function if the mouse is moved over certain areas of the movie clip on
stage. Based on which area of the movie clip the mouse is moved I'd like to be able to trigger
different behaviour. Below is the code which I was thinking shoud do it:
Code:
var posY:Number;
var mouseListener:Object = new Object();
mouseListener.onMouseMove = function() {
posY = mcArea._ymouse;
if (posY >= 140 || posY <= 170){
trace ("+0");
}else if (posY > 171 || posY < 190){
//trace ("+1");
}else if (posY == 192 || posY == 212){
trace ("+2");
}else if (posY > 213 || posY < 233){
//trace ("+3");
}else if (posY > 234 || posY < 254){
//trace ("+4");
}else if (posY > 275 || posY < 295){
//trace ("+5");
}else if (posY > 296 || posY < 316){
//trace ("+7");
}else if (posY > 317 || posY < 340){
//trace ("+8");
}
}
Mouse.addListener(mouseListener);
For some reason, the trace statement is ran always when the mouse moves regardless if it is over the
movie clip or not. It also only shows the first trace statement. It is never chaged even if the mouse
is in the different areas of the movie clip. I am wondering if someone can give me an advice on how to
fix it.
Thank you in advance!
-
Senior Member
The problem is that you are using the logical OR operator rather than the logical AND operator. Switch all your ||'s to &&'s and it should work.
-
PHP Code:
var posY:Number=0;
var mouseListener:Object = new Object(); mouseListener.onMouseMove = function() {
if (mcArea.hitTest(_root._xmouse, _root._ymouse, true)) { posY = mcArea._ymouse; if (posY >= 140 && posY <= 170){ dyn = "+0"; }else if (posY > 171 && posY < 190){ dyn = "+1"; }else if (posY > 192 && posY < 212){ dyn = "+2"; }else if (posY > 213 && posY < 233){ dyn = "+3"; }else if (posY > 234 && posY < 254){ dyn = "+4"; }else if (posY > 275 && posY < 295){ dyn = "+5"; }else if (posY > 296 && posY < 316){ dyn = "+7"; }else if (posY > 317 && posY < 340){ dyn = "+8"; } }
} Mouse.addListener(mouseListener);
and a hitTest for the 'above mc only'
removed the comments on the traces, also added a dynamic field, the constant tracing gets annoying.
gparis
-
Great. It works perfectly. Thank you a lot for the help.
-
Last edited by vladc77; 09-23-2009 at 03:04 PM.
Best regards
Vlad,
-
you're doubly welcome!
gparis
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|