嵌套的 movieClips 未检测到 Actionscript 中的鼠标事件

发布于 2024-08-27 08:26:33 字数 667 浏览 7 评论 0原文

我有一些嵌套的影片剪辑。我在父级上有一个事件侦听器,用于侦听鼠标单击。问题是,听者永远不会听到咔嗒声。

代码:

    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
    }

在 movieClipStack 上,我可以看到 mouseEnabled = true。此外,buttonMode = true 的工作方式与预期的完全一样。但 onStackClicked 永远不会发生 - movieClipStack 只是没有检测到任何类型的鼠标事件。

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

骷髅 2024-09-03 08:26:33

一些想法...

首先检查以确保movieClipStack.mouseEnabled == true,只是为了确保您不会无意中禁用从鼠标到对象的消息。

然后我会使用 trace( movieClipStack.hitArea ); 查看您为 movieClipStack 设置的 hitArea。检查其 widthheight 值,看看它是否大致等于您期望的 movieClipStack 的宽度和高度。

然后我尝试创建一个简单的矩形精灵并将其设置为 movieClipStackhitArea

我希望这有效。祝你好运!

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!

枕梦 2024-09-03 08:26:33

有一个鲜为人知的属性,称为“mouseChildren”,您必须为鼠标监听影片剪辑的内容元素设置该属性。

如果您不从事件流中删除这些其他元素,它们往往会以不可预测的方式使事件黯然失色。

因此,您可以这样分配它:

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

如果您将其放入 MovieClip 或类定义中,我通常会这样做:

 mouseChildren = false;

另外,这里有一篇 Adob​​e 文章解释了整个事情:
http://www.adobe.com/livedocs/ flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html

希望这有帮助!我花了好长时间才终于发现这个。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文