6 Replies Latest reply on Dec 15, 2010 2:22 AM by blacksyforce

    addEventListener Problem

    blacksyforce Level 1

      Hy, I have a movie clip created in flash that has several other movie clips inside. When I try to add an event listener for Mouse_Over it adds that event for every single movie clip i have in my big movie clip. Can anyone help ?



        • 1. Re: addEventListener Problem
          commadelimited Level 2

          If you do some testing, you'll probably find that it's not actually adding the event for the children, it's just that the mouseover event for the parent is behaving like the children have it too.

          • 2. Re: addEventListener Problem
            blacksyforce Level 1

            Yes, but I don't want to behave like that. I'm thinking of adding an EventListener into the parent (it won't add the behavior to the children) and when it triggers it will throw an Event and Flex will catch it. But I don't like this solution, too complicated and I have poor control here.


            Do you have any suggestion ?

            • 3. Re: addEventListener Problem
              imdfl Level 1

              What are you trying to achieve? Do you want to get mouseover only when the mouse is over a part of the parent that is not occupied by a child? In any case, this is a Flash issue, not AIR.

              • 4. Re: addEventListener Problem
                blacksyforce Level 1

                My code is something like this:


                public class CustomObject extends UIMovieClip


                     private var avatar:UIMovieClip;


                     public function CustomObject(image:UIMovieClip)


                          avatar = image;







                var object:CustomObject = new CustomObject( new AvatarObject);


                object.addEventListener(MouseEvent.MOUSE_OVER, eventOver);

                object.addEventListener(MouseEvent.MOUSE_OUT, eventOut);


                function mouseOver(e:MouseEvent):void


                     //play animation



                function mouseOut(e:MouseEvent):void


                     //stop animation



                I want to play the animation when the mouse is over my object and stop when the mouse leaves it. But when the users moves over the parent but from a child to another the MOUSE_OUT event is triggered. I don't want that to happen, the children shouldn't have this behavior, only the parent object. I don't even understand why they have this behavior.

                • 5. Re: addEventListener Problem
                  imdfl Level 1



                  It's possible that your object has 'holes' in it, i.e. that it contains children but nothing between them. In this case, mouse movements between the children will generate mouse in/out events. If this is the case, simply add a transparent shape in the background of the object.


                  If this is not the case - do you need any kind of mouse interaction for the children? If not, you can just add

                  object.mouseChildren = false;


                  If both tips don't work - this is not likely but just in case - why not check the value of the mouse event's currentTarget property? If it's not the AvatarObject but rather one of its children, ignore the event.

                  • 6. Re: addEventListener Problem
                    blacksyforce Level 1

                    Yurika ! Thanks imdfl (^^,)


                    My object has an irregular shape and is an animation so I can't add a transparent shape, but object.mouseChildren = false did the job.