AS3事件在Scenegraph / DisplayList外面冒泡 [英] AS3 Event Bubbling outside of the Scenegraph/DisplayList

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

问题描述

您好只是想知道是否可以利用AS3中的非显示列表类中的事件冒泡。

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

例如在应用程序的模型中,一个包含许多汽车的城市课。有什么方法可以将事件侦听器附加到City对象,并接收从小汽车冒出来的事件。澄清City和Car对象不是显示列表的一部分,它们不是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?

据我所知,如果没有手动将事件侦听器附加到每个Car对象并从City对象重新分派事件,这是不可能的。任何人都有清洁的解决方案?

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/flex/3/html/help.html?content=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/flex/3/html/help.html?content=events_08.html

捕获和冒泡发生在Event对象从显示列表中的节点移动到另一个节点时:用于捕获的parent-to-child和用于冒泡的child-to-parent。这个过程与继承层次无关。除了目标阶段之外,只有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事件在Scenegraph / DisplayList外面冒泡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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