3 Replies Latest reply: Aug 9, 2011 11:30 AM by Mongo345678 RSS

    Mouse_OUT and a pop-up menu

    Mongo345678 Community Member

      Hey I'm building a basic popup menu from scratch.

      I have an MC on my stage (button2) which has certain properties.

      What I want is to hover over the button and get a bunch of child buttons appear above the button. This works fine, except I cannot get the mouse_out to work properly on the child buttons. I want to be able to move my cursor across the various child buttons, but when I actually move the cursor outside the container of the child buttons that is when I want them to disappear. Right now what's happening is if I mouse_out from ANY child button, they disappear.

       

      In frame 1, I have the following script:

       

      import flash.display.MovieClip;
      
      stop();
      
      var posY;
      var label_num_string:String;
      var label_num_first:String;
      var label_num_sub:String;
      
      // sets up array to hold sub-menu MC's
      var submenus_array:Array = [];
      
      button2.addEventListener(MouseEvent.CLICK, mouseClickHandler);
      button2.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
      //button2.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
      button2.buttonMode = true;
      button2.useHandCursor = true;
      button2.buttonText.text = "parent button"
      button2.buttonText.mouseEnabled = false;
      
      if (button2.submenu == true) {
           var submenu:MovieClip = new MovieClip();
           
           submenus_array[2] = submenu;          
           submenus_array[2].y = button2.y - button2.height;
           submenus_array[2].name = "submenu" + i;
           
           posY = 0;
           
           for(var i:uint=1; i<4; i++) {
                var bt:MovieClip = new MenuButton();
                bt.y = posY;
                posY -= bt.button_bg.height;
                bt.x = button2.x;
                bt.buttonText.text = "child button";
                bt.mouseChildren = false;
                bt.buttonMode = true;
                
                bt.addEventListener(MouseEvent.CLICK,mouseClickHandler);
                //bt.addEventListener(MouseEvent.MOUSE_OVER,handleMouseOver);
                //bt.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
      
                submenus_array[2].addChild(bt);
           }
      }
      
      function mouseClickHandler(e:MouseEvent):void {
       //blah
      }
      
      function mouseOutHandler(e:MouseEvent):void {
                if(stage.contains(submenus_array[2])) {
                     stage.removeChild(submenus_array[2]);
                }
      }
      
      function mouseOverHandler(e:MouseEvent):void {
           if(stage.contains(submenus_array[2])) {
                     
           } else {
                stage.addChild(submenus_array[2]);
                submenus_array[2].addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
           }
      }
      
        • 1. Re: Mouse_OUT and a pop-up menu
          kennethkawamoto2 CommunityMVP

          One way is to place a background covers the entire region in "submenu" MovieClip.

          • 2. Re: Mouse_OUT and a pop-up menu
            martinjamesroberts1 Community Member

            convert button2 to a movieclip (if it isn't already) and add you submenu inside the movieclip.. that way your ROLL_OVER will reveal the submenu and the submenu will be part of button2, meaning ROLL_OUT will not be called unless you roll off of the menu completey..

            • 3. Re: Mouse_OUT and a pop-up menu
              Mongo345678 Community Member

              Holy cow I found out, after so many days yeesh.

               

              I did have to re-do how I handled the container MC for submenu's and the array to store all the MC's...

               

              But in the end the problem was this:

               

              I had to use ROLL_OUT on the parent MC (the container of the submenu), rather than MOUSE_OUT.

               

              Using MOUSE_OUT would apply to the parent MC and all of it's children. The only way for that not to happen is if I used mouseChildren = false... but then I wouldn't be able to register clicks on my children.

               

              Using ROLL_OUT worked like a charm... it applies to only the entire area of the parent MC, but I still keep the other listener functionality in the children.

               

              I was going bonkers trying to fix this, it feels good now.