How to listen to Flash events that don’t bubble

Jacob Wright
March 3rd, 2008

I learned a little trick the other week and thought I’d share. Sometimes you might need to listen to a non-bubbling event “up the chain” somewhere, but of course, since it is not bubbling, that can be hard. The trick is that event events that don’t have bubbling still have the capture phase, so if you flip that capture flag to true in the event listener then you can now listen to any events dispatched by any child views whether they are bubbling or not.

Example:

// listen for some event (this one is even custom) that does not bubble
// make sure to set true on capture
stage.addEventListener(”customNonBubbling”, myListener, true);

<mx:Button id=”myButton” click=”dispatchEvent(new Event(’customNonBubbling’))”/>

Note: this only works on display objects as far as I know. Capture and bubbling don’t apply to objects that are not on the display list.

One Response to “How to listen to Flash events that don’t bubble”

  1. Tony Fendall Says:

    That’s awesome. Thank you!

Leave a Reply