嵌套的 movieClips 未检测到 Actionscript 中的鼠标事件
我有一些嵌套的影片剪辑。我在父级上有一个事件侦听器,用于侦听鼠标单击。问题是,听者永远不会听到咔嗒声。
代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些想法...
首先检查以确保movieClipStack.mouseEnabled == true,只是为了确保您不会无意中禁用从鼠标到对象的消息。
然后我会使用
trace( movieClipStack.hitArea );
查看您为movieClipStack
设置的hitArea
。检查其width
和height
值,看看它是否大致等于您期望的movieClipStack
的宽度和高度。然后我尝试创建一个简单的矩形精灵并将其设置为
movieClipStack
的hitArea
。我希望这有效。祝你好运!
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 formovieClipStack
withtrace( movieClipStack.hitArea );
. Check itswidth
andheight
values to see if it's roughly what you would expect the width and height ofmovieClipStack
to be.Then I'd experiment with creating a simple rectangular sprite and setting it as the
hitArea
formovieClipStack
.I hope that works. Good luck!
有一个鲜为人知的属性,称为“mouseChildren”,您必须为鼠标监听影片剪辑的内容元素设置该属性。
如果您不从事件流中删除这些其他元素,它们往往会以不可预测的方式使事件黯然失色。
因此,您可以这样分配它:
如果您将其放入 MovieClip 或类定义中,我通常会这样做:
另外,这里有一篇 Adobe 文章解释了整个事情:
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:
If you were putting this inside the MovieClip, or inside a class definition, I usually just do it this way:
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.