开发者

Nested movieClips not detecting mouse events in Actionscript

开发者 https://www.devze.com 2022-12-25 00:09 出处:网络
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.

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;
 开发者_JS百科       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 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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号