views:

372

answers:

2

I have some nested movieClips. I've got an event listener on the parent listening for a mouse click. Problem is, the listener never picks up the click.

Code:

    var movieClipStack:MovieClip = new MovieClip();

    for each (var ol:OwnedLayerable in owned_layerables)
    {
        var mc:MovieClip = ol.layerable.mc;
        movieClipStack.buttonMode = true;
        movieClipStack.addChild(mc);
    }

    movieClipStack.addEventListener(MouseEvent.CLICK, onStackClicked);

    private function onStackClicked(evt:MouseEvent):void
    {
        // Do some stuff
    }

On movieClipStack, I can see that mouseEnabled = true. In addition, buttonMode = true works exactly like it's supposed to. But onStackClicked never happens - movieClipStack just isn't detecting any sort of mouse event.

Thanks!

A: 

A couple ideas...

First check to make sure that movieClipStack.mouseEnabled == true, just to make sure that you aren't inadvertently disabling messages from the mouse to your object.

Then I'd take a look at what hitArea you have set for movieClipStack with trace( movieClipStack.hitArea );. Check its width and height values to see if it's roughly what you would expect the width and height of movieClipStack to be.

Then I'd experiment with creating a simple rectangular sprite and setting it as the hitArea for movieClipStack.

I hope that works. Good luck!

Thomas
A: 

There is a little known property called "mouseChildren" that you must set for the content elements of your mouse-listening movieclip.

If you do not remove those other elements from the event stream, they tend to eclipse events in a not-so-predictable way.

So, you would assign it like this:

 parentMovieClip.mouseChildren = false;// turns off all internal mouse-listening clips

If you were putting this inside the MovieClip, or inside a class definition, I usually just do it this way:

 mouseChildren = false;

Also, here is an Adobe article explaining the whole thing: http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html

Hope this helps! It took me HOOOOOOOURS to finally unearth this one.

exoboy