Custom broadcast events in AS3?
Posted
by Ender
on Stack Overflow
See other posts from Stack Overflow
or by Ender
Published on 2010-03-15T06:05:48Z
Indexed on
2010/03/15
6:09 UTC
Read the original article
Hit count: 493
In Actionscript 3, most events use the capture/target/bubble model, which is pretty popular nowadays:
When an event occurs, it moves through the three phases of the event flow: the capture phase, which flows from the top of the display list hierarchy to the node just before the target node; the target phase, which comprises the target node; and the bubbling phase, which flows from the node subsequent to the target node back up the display list hierarchy.
However, some events, such as the Sprite class's enterFrame
event, do not capture OR bubble - you must subscribe directly to the target to detect the event. The documentation refers to these as "broadcast events." I assume this is for performance reasons, since these events will be triggered constantly for each sprite on stage and you don't want to have to deal with all that superfluous event propagation.
I want to dispatch my own broadcast events. I know you can prevent an event from bubbling (Event.bubbles = false
), but can you get rid of capture as well?
© Stack Overflow or respective owner