简体   繁体   中英

AS3 - Make ADDED_TO_STAGE Capture/Bubble?

So the *ADDED_TO_STAGE* and *REMOVED_FROM_STAGE* Events do not notify ancestors in any way. 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.

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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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