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:
…
<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.
That’s awesome. Thank you!
I have a question and will try to ask using an example.
Suppose, I have a main class called and then I have something called as a child of and then I have as a child of and they are all added to display list.
Now, if dispatches event and the is set to and I have a listener attached to all three classes (i.e. , and ) for that particular event type , what would be the event flow order?
Say I had a in the listener functions in those three classes, what would be the trace order?
You can learn more about event handling here: http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html
If you’re listening on the capture phase then the closer you are to root, the sooner you’ll handle the event. If you’re just listening normally then the closer you are to the target the sooner you’ll handle the event.
[...] 真不知道那个Flash不用处理帧和鼠标点击。 http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html http://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.html http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
Nice tip thx !
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] 3. Player Events, Custom Events, Event Bubbling I can’t imagine where flash player would be without frames and mouse clicks. http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html http://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.html http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html http://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.html http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] 3. Player Events, Custom Events, Event BubblingI can’t imagine where flash player would be without frames and mouse clicks.http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.htmlhttp://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.htmlhttp://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ 4. Statements, Keywords, and Directives You should never be [...]
[...] 3. Player Events, Custom Events, Event Bubbling I can’t imagine where flash player would be without frames and mouse clicks. http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html http://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.html http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]
[...] 3. Wykonywanie zdarzeń (Player Events, Custom Events, Event Bubbling) Chyba jedyny język programowania który ma listwę czasową, klatki oraz nasłuchiwanie zdarzeń. http://www.adobe.com/devnet/actionscript/articles/event_handling_as3_03.html http://livedocs.adobe.com/flex/3/langref/flash/events/package-detail.html http://www.tink.ws/blog/custom-events-in-as-30-dont-forget-to-override-the-clone-method/ http://jacwright.com/blog/70/how-to-listen-to-flash-events-that-dont-bubble/ [...]