AS3事件冒泡的场景图/图像显示之外 [英] AS3 Event Bubbling outside of the Scenegraph/DisplayList

查看:222
本文介绍了AS3事件冒泡的场景图/图像显示之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨只是想知道是否有可能利用的事件冒泡非显示列表类的AS3。

Hi just wondering if it is possible to take advantage of event bubbling in non display list classes in AS3.

例如在应用程序,其中有包含许多汽车一类城市的模型。有什么方法那里事件侦听器附加到一个城市的对象和接收事件,从儿童汽车泡沫了。澄清市及汽车对象不是显示列表的一部分,他们不是的DisplayObject。所以可以将气泡显示列表之外的某种方式来实现?

For example in the model of an application where there is a City class that contains many Cars. What methods are there to attach an event listener to a City object and receive events that bubble up from the child Cars. To clarify The City and Car objects are not part of the display list, they are not DisplayObjects. So can bubbling be implemented outside of the display list somehow?

据我所知,这是不可能的,而无需手动安装事件侦听器,以每辆车对象并重新调度从市对象的事件。任何人有一个更清洁的解决方案吗?

As far as I know, this is not possible without manually attaching event listeners to each Car object and re dispatching the event from the City object. Anyone else have a cleaner solution?

推荐答案

我不知道我完全理解,但是当你创建一个事件,你可以说它泡沫,因此,当调度它将泡沫。

I'm not sure I am fully understanding, but when you create an event you can say that it bubbles and so when it dispatches it will bubble.

HTTP://livedocs.adobe。 COM /柔性/ 3 / HTML / help.html?内容= createevents_3.html

的http:// LiveDocs中。 adobe.com/flex/3/langref/flash/events/Event.html#Event()

我相信这将让你一个事件侦听器附加到你所在城市的权利类型的事件,这会赶上抛出车事件。我还没有尝试过这虽然让我不知道。

I believe that would allow you to attach an event listener to your city for the right types of events and that would catch events thrown by cars. I haven't ever tried this though so I am not sure.

更新:

嗯,我没有意识到这一点。你是对的。从以下链接:

Ah, I didn't realize this. You are correct. From the following link:

HTTP://livedocs.adobe。 COM /柔性/ 3 / HTML / help.html?内容= events_08.html

捕获和冒泡发生,因为从节点的事件对象移动到节点的显示列表中:家长对孩子捕获和儿童对父母的冒泡。这个过程有没有关系的继承层次结构。仅DisplayObject对象(可视对象如容器和控制)可以具有捕捉相位和除了靶向相冒泡相

Capturing and bubbling happen as the Event object moves from node to node in the display list: parent-to-child for capturing and child-to-parent for bubbling. This process has nothing to do with the inheritance hierarchy. Only DisplayObject objects (visual objects such as containers and controls) can have a capturing phase and a bubbling phase in addition to the targeting phase.

我可以解决这个看到的唯一办法是您注册子与父(汽车与城市)的每一个新加入作为一个孩子的时间。在这一点上,你可以在父(市)添加事件侦听器,然后重新发送从父(市)一个事件从子(车)处理的任何时间的事件。它的丑陋,我知道了,你会想确保你删除,你删除一个孩子的事件侦听器在任何时间,但它是唯一真正的解决办法,我可以看到。

The only way I can see around this would be for you to register the child with the parent (the car with the city) every time a new one is added as a child. At that point you could add an event listener in the parent (city) and then re-dispatch an event from the parent (city) any time a event is handled from the child (car). Its ugly I know, and you would want to make sure you remove the event listener anytime that you remove a child, but it's the only real solution I can see.

这篇关于AS3事件冒泡的场景图/图像显示之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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