raghav
raghav

Reputation: 362

MouseEvent not dispatching on movie clip

I know this must be easy but somehow I have not been able to figure it out after spending more than hours. I have two movie clips in a class that extends Sprite. When I add event listener to the stage every thing works fine. But when I try to add event listener to one of the movie clips, the event never dispatches it seems. Here is how it looks like -

public class MyClass extends Sprite
{
    private var movieclip1:MovieClip, movieclip2:MovieClip;

    private function init(e:Event == null):void
    {
         movieclip1 = new MovieClip();
         movieclip2 = new MovieClip();
         //works fine, dispatches event
         stage.addEventListener(MouseEvent.MOUSE_DOWN. mousedown);
         //not working
         movieclip1.addEventListener(MouseEvent.MOUSE_DOWN, mousedown);
         addChild(movieclip1);
         addChild(movieclip2);
    }
}

Actually I want both the movie clips to work mutually exclusively, i.e., a mouse event on one movie clip should not interfere with that of the other. Any pointers?

Upvotes: 0

Views: 89

Answers (2)

SharpEdge
SharpEdge

Reputation: 1762

Empty MovieClips and Sprites CANNOT be sized, they will be 0,0 and then they will not be able to dispatch MouseEvents.

You can resize a MovieClip when it has some content. The Sprite will be of the size of the rectangle that encloses the 2 MovieClip.

If the MovieClips are empty = 0,0 the Sprite will be 0,0

About the events between the 2 MovieClips: They are not going to interfere because the events when are bubbling goes upwards.

So the listeners put on MC1 will listen ONLY onClick on MC1 and the same does MC2

Upvotes: 2

chenze
chenze

Reputation: 21

You can trace the width and height of the movieclip1 or movieclip2, you will get 0 both. So, you can't click them.

You can use graphcis to draw a shape in these two mcs, and try again.

Upvotes: 1

Related Questions