A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Changing behavior based on Y, X coordinates over a Movie Clip with onMouseMove

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180

    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!
    Best regards
    Vlad,

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    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.
    New sig soon

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    PHP Code:
    var posY:Number=0;


    var 
    mouseListener:Object = new Object();
    mouseListener.onMouseMove = function() {

        if (
    mcArea.hitTest(_root._xmouse_root._ymousetrue)) {
            
    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

  4. #4
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Great. It works perfectly. Thank you a lot for the help.
    Best regards
    Vlad,

  5. #5
    Senior Member
    Join Date
    Aug 2001
    Location
    Seattle, WA
    Posts
    180
    Thanks.
    Last edited by vladc77; 09-23-2009 at 03:04 PM.
    Best regards
    Vlad,

  6. #6
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center