Bubbling events is generally a bad practice. Bubbling should be reserved
for events that can be dispatched my more than one children of varying types
within a container. That's why only things like adding/removing children,
mouse and keyboard activity and focus bubble.
Capture is used by a container to react to an event and possibly prevent the
actual target's listeners from seeing it. It's primary use is in handling
mouse dragging, similar to the MouseCapture() API in Windows.
Alex, why is bubbling events considered bad practice? I am really curious because I make heavy use of bubbling to send information to the systemManager to act as a controller.
Also seems useful to me as a way to more loosely couple components. But, I am not trying to be combative or defensive, just explaining why I use bubbling.
APPLICATION_COMPLETE is only dispatched from the Application and
SystemManager. If you are not listening there you won't see it.
Note that, if you had a sub-app that bubbled APPLICATION_COMPLETE, the
main-app would see it and potentially run its APPLICATION_COMPLETE handlers
again, which is probably not desirable.
It is exactly my case.
I have loader class and sup-application(s) it loads. Loader needs to know when sub-app
finishes its initialization (APPLICATION_COMPLETE event happened) in order to invoke
sub-app.methods. So, loader in Event.COMPLETE handler has:
public function onSubappLoaded( event:Event ):void
var swfLoader:SWFLoader = event.target as SWFLoader;
swfLoader.removeEventListener( Event.COMPLETE, onSubappLoaded );
swfLoader.removeEventListener( IOErrorEvent.IO_ERROR, onSubappLoadError );
loadedApp = event.target.content as ISystemManager;
if ( loadedApp != null )
loadedApp.addEventListener( FlexEvent.APPLICATION_COMPLETE, onSubappConstructed, false, 3 );
public function onSubappConstructed( event:FlexEvent ):void
loadedApp.removeEventListener( FlexEvent.APPLICATION_COMPLETE, onSubappConstructed );
// cast the loaded application to the interface it implements
var loadable:ISCCLoadable = event.currentTarget.application as ISCCLoadable;
sccLoadable = loadable as ISCCLoadable;
}So, my question was, is it correct to add listener as above or it is better to changeto ddEventListener( FlexEvent.APPLICATION_COMPLETE, onAppConstructed, true );Thank you very much
Sorry, Alex, It was typo in my previous post. What I meant to ask was:
In sub-app loader should I listen APPLICATION_COMPLETE event
addEventListener( FlexEvent.APPLICATION_COMPLETE, onSubappConstructed, true );
or like this:
addEventListener( FlexEvent.APPLICATION_COMPLETE, onSubappConstructed, false );
or it does not matter?