as3 mouseEnabled 对我来说仍然是个问题 [英] as3 mouseEnabled still a problem for me

查看:20
本文介绍了as3 mouseEnabled 对我来说仍然是个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几年过去了,我仍然没有理解关于 mouseEnabled 的一些东西.我有一个精灵(例如这里的天空",它包含许多对象,其中一个是云,我不想接收鼠标事件.我将此天空覆盖在其他一些显示对象上.我希望云是可见,但不会阻止鼠标事件.如果您看到一棵树穿过云层,您应该能够点击该树.

在天空课堂:

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

即使使用这种配置,当云在树上时我也无法点击树,因为云挡住了它.为什么???

解决方案

即使 Sky 将 mouseEnabled/mouseChildren 设置为 false...它仍然是一个对象,它仍然占用空间,因此仍然充当任何没有将 mouseEnabled/mouseChildren 设置为 false 的 PARENT 容器.

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

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

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

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

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

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???

解决方案

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 :)

这篇关于as3 mouseEnabled 对我来说仍然是个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆