简体   繁体   English

AS3-进行ADDED_TO_STAGE捕捉/冒泡?

[英]AS3 - Make ADDED_TO_STAGE Capture/Bubble?

So the *ADDED_TO_STAGE* and *REMOVED_FROM_STAGE* Events do not notify ancestors in any way. 因此,* ADDED_TO_STAGE *和* REMOVED_FROM_STAGE *事件不会以任何方式通知祖先。 I've looked all around and can't find an answer...do I need to build a new class to do it, or is there a way to hack it into using the Capture/Bubble notification phases? 我四处张望,找不到答案...我需要建立一个新的类来完成此操作,还是可以使用“捕获/气泡”通知阶段来破解它?

The descendants of a DisplayObject that is removed from the stage dispatches it's own REMOVED_FROM_STAGE and ADDED_FROM_STAGE events when their parent is removed from the display list of the stage. 从舞台中移除的DisplayObject的后代在其父级从舞台的显示列表中移除时,将调度自己的REMOVED_FROM_STAGEADDED_FROM_STAGE事件。

So you can simply add an event listener to any descendant and have it handle those events directly. 因此,您可以简单地将事件侦听器添加到任何后代,并使其直接处理这些事件。

I may be misunderstanding what you are trying to do, but in general events bubble upward from child objects to their parents. 我可能会误解您想做的事情,但总的来说,从儿童物品到父母的事情冒出了泡沫。 So when you say the descendants are not notified, you are correct as they are not upward on the heiarchy. 因此,当您说未通知子孙后代时,您是正确的,因为他们的继承权并不高。 However, if your goal is for a given object to know when it is added/removed to/from the display list of the stage, that can be had by listening to the specific DisplayObject . 但是,如果您的目标是让给定对象知道何时将其添加到舞台的显示列表中/从舞台的显示列表中删除,则可以通过侦听特定的DisplayObject

So although the added/removed events do not bubble to their ancestors, there is a way to listen for their events directly. 因此,尽管添加/删除的事件不会冒泡给他们的祖先,但是有一种方法可以直接监听他们的事件。

And if you subclassed MovieClip or Sprite, you could have that class listen for the event, and then dispatch an event that does bubble to the ancestors. 而且,如果您将MovieClip或Sprite子类化,则可以让该类侦听该事件,然后分派一个确实冒泡给祖先的事件。

However, I think it be better for us to understand better what you are trying to do as your approach might be the real issue. 但是,我认为最好是让我们更好地了解您正在尝试做的事情,因为您的方法可能是真正的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM