as3 mouseEnabled 对我来说仍然是一个问题
几年过去了,我仍然没有得到关于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使 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 :)
你说里面有“很多东西”?很可能有其他东西阻碍了它。我建议在舞台上添加一个侦听器,然后您可以看到哪个对象正在接收点击:
发布更多代码,我们可能可以提供更多帮助。
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:
Post more code and we can probably help more.