as3 mouseEnabled 对我来说仍然是一个问题

发布于 2024-08-21 09:41:52 字数 304 浏览 9 评论 0原文

几年过去了,我仍然没有得到关于 mouseEnabled 的一些信息。我有一个精灵(例如这里的“天空”,其中包含许多对象,其中之一是云,我不想接收鼠标事件。我将这个天空覆盖在其他一些显示对象上。我希望云成为可见,但不能阻止鼠标事件。如果您透过云看到一棵树,您应该能够单击该树:

即使使用

mouseEnabled = false;
cloud.mouseEnabled = false;
cloud.mouseChildren = false;

此配置,当云位于树上方时,我也无法单击 该树。树因为云挡住了它?

A couple years in now, there's still something about mouseEnabled I'm not getting. I have a Sprite (for example here "Sky", that contains many objects, one of them is a Cloud, which I do not want to receive Mouse Events. I overlay this Sky on some other display objects. I want the cloud to be visible, but not to block mouse events. If you see a tree through the clouds you should be able to click on the tree.

In the Sky class:

mouseEnabled = false;
cloud.mouseEnabled = false;
cloud.mouseChildren = false;

Even with this configuration, when the cloud is over the tree I can't click on the tree because the cloud blocks it. Why???

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

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

发布评论

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

评论(2

风筝有风,海豚有海 2024-08-28 09:41:52

即使 Sky 将 mouseEnabled/mouseChildren 设置为 false...它仍然是一个对象,它仍然占用空间,因此仍然充当任何未将 mouseEnabled/mouseChildren 设置为 false 的父容器的点击区域。

因此,我怀疑您的 Sky 对象与 Tree 对象不在同一父容器中。您的 Sky 对象可能有自己的父容器对象,它是拦截事件的罪魁祸首。

详细说明:任何包含 ANYTHING 的对象都会有一个点击区域,并且会拦截鼠标点击,即使它包含的所有单个对象(形状、子对象等)可能将 mouseEnabled/mouseChildren 设置为 false。

因此,即使您的 Sky 对象将 mouseEnabled 设置为 false,您的 Sky(及其子对象)仍然占用空间,因此仍然为 Sky 的父容器提供了一个点击区域来拦截鼠标事件。

因此,您的解决方案是确保 Sky 的所有父容器的 mouseEnabled 属性设置为 false,至少直到(但不包括)Tree 和 Sky 对象的第一个公共祖先容器。

另外,通过设置 mouseEnabled=false 并保留 mouseChildren=true,您可以拥有一个容器,其中仅选择 mouseEnabled=true 的子项接收单击事件:)

Even though Sky has mouseEnabled/mouseChildren set to false... it's still an object, it still takes up space, and therefore still acts as a hit area for any PARENT containers that don't have mouseEnabled/mouseChildren set to false.

Therefore, I suspect your Sky object is not in the same parent container as your Tree object. Your Sky object probably has its own parent container object, which is the culprit intercepting the events.

To elaborate: Any object that contains ANYTHING will have a hit area and will intercept mouse clicks, even though all the individual things it contains (shapes, child objects, etc.) may have mouseEnabled/mouseChildren set to false.

So even though your Sky object has mouseEnabled set to false, your Sky (and it's children) still take up space, and therefore still give Sky's parent container a hit area to intercept mouse events.

Your solution, therefore, is to make sure all the parent containers of Sky have thier mouseEnabled property set to false, at least up to (but not including) the first common ancestor container of the Tree and Sky objects.

Also, by setting mouseEnabled=false and leaving mouseChildren=true, you can have a container where only select children with mouseEnabled=true receive click events :)

故事↓在人 2024-08-28 09:41:52

你说里面有“很多东西”?很可能有其他东西阻碍了它。我建议在舞台上添加一个侦听器,然后您可以看到哪个对象正在接收点击:

import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
    trace(event.target.name, getQualifiedClassName(event.target));
}

发布更多代码,我们可能可以提供更多帮助。

You say there's "many objects" in there? More than likely something else is blocking it. I recommend adding a listener to the stage and then you can see which object is receiving clicks:

import flash.utils.getQualifiedClassName;
stage.addEventListener(MouseEvent.CLICK, onClick);
private function onClick(event:MouseEvent):void
{
    trace(event.target.name, getQualifiedClassName(event.target));
}

Post more code and we can probably help more.

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