5 Replies Latest reply on Jun 1, 2010 11:36 AM by flairjax

    mousechildren = false???

    flairjax Level 1

      In my current project, I have mouseChildren = 'false' on the mainSprite because the mainSprite contains an image and I need the mainSprite to hear the mousDown events. If I set mouseChildren = 'true' then the mainSprite doesn't end up hearing the mouseDown event so doesn't respond appropriately.  Setting mouseChildren = 'false' was fine as the image didn't need to hear mouseEvents, but now the requirements of the app have changed.


      So now instead of just adding an image I have to add a couple of more sprites with some navigation and other elements. So now I can't set mouseChildren = 'false' because then the newly added sprites/menus won't hear the mouseOver. But now the mainSprite doesn't hear the mouseDown.


      How can I get the mainSprite to hear the mouseDown, but keep the other mouseEvents for the children of mainSprite?


      TIA, J

        • 1. Re: mousechildren = false???
          Flex harUI Adobe Employee

          Mouse events bubble, so the main sprite should still hear it.  How are you

          attaching your listener?

          • 2. Re: mousechildren = false???
            flairjax Level 1

            mainSprite.addEventListener(MouseEvent.MOUSE_DOWN, handleHighlighting );

            mainSprite.addEventListener(MouseEvent.ROLL_OVER, handleHighlighting );

            mainSprite.addEventListener(MouseEvent.ROLL_OUT, handleHighlighting );


            public function handleHighlighting(e:MouseEvent):void

                            case MouseEvent.MOUSE_DOWN:
                            case MouseEvent.MOUSE_UP:
                            case MouseEvent.ROLL_OVER:
                                //do something
                            case MouseEvent.ROLL_OUT:
                                //do something
                            default : break;

            • 3. Re: mousechildren = false???
              flairjax Level 1

              So my eventlistner that is to be called on MouseDown shows the event.target as my image and not the mainSprite.

              • 4. Re: mousechildren = false???
                Flex harUI Adobe Employee

                I'm not sure if setting width/height on a loader makes a difference until it

                has content, so maybe it has an unexpected size.   Check out its

                width/height in the mouse event handler.


                Sounds like you are in fact getting mouse events even with


                • 5. Re: mousechildren = false???
                  flairjax Level 1

                  Ok, think I have it.  I use the code below to add my image to mainSprite. This image is the "loader" that is getting all the mouseEvents.  Once I set mouseChildren = false (see last line below) then it works as appropriate.  I guess the way I am importanting the images via css (code not shown) somehow underneath the covers is using a loader because I am not explicitly calling or instanciating a loader for this icon image.



                  var _imgClass:Class;
                              var _image:Sprite;

                  _image = new _imgClass();
                                      _image.name = 'icon';
                                      n.data.type == "Cloud" ? _image.scaleX = 0.65 : _image.scaleX = 0.5;
                                      n.data.type == "Cloud" ? _image.scaleY = 0.65 : _image.scaleY = 0.5;
                                      _image.x = -1 * ( (_image.width/2) * _image.scaleX );
                                      _image.y = -1 * ( (_image.height/2) * _image.scaleY );
                                      _image.cacheAsBitmap = true;
                                      n.addChildAt( _image, 0 );
                                      _image.mouseEnabled = false;
                                      _image.mouseChildren = false;



                  As always, thanks for you help Alex!!!