I made a custom event called TreeDataLoadedEvent.
In my Application.mxml, i add a listener to this event in the
creationComplete phase.
The TreeDataLoadedEvent is dispatched by a custom class named
ModelLocator that extends EventDispatcher.
The ModelLocator class is instanced in Application.mxml.

It seems that Application.mxml does not receive the event at all...
I wonder if it is because ModelLocator is not directly a child of the
main application...?

How i can dispatch an event to the application that is not a child of
type DisplayObject?

Code :

<mx:Application
     xmlns:mx="http://www.adobe.com/2006/mxml";
     layout="absolute"
     creationComplete="creationCompletedHandler(event);">

     <mx:Script>
         <![CDATA[
             import events.TreeDataLoadedEvent;
             import model.ModelLocator;
             import mx.controls.Alert;

             public var modelLocator:ModelLocator =
ModelLocator.getInstance();

             private function creationCompletedHandler(evt:Event):void{
                 this.addEventListener(
TreeDataLoadedEvent.LOAD_COMPLETED_EVENT, eventReceived );
             }

             private function btnClicked(evt:Event):void{
                 modelLocator.dispatchEvent( new TreeDataLoadedEvent()
);// In the constructor i call super("goodType",true)
             }

             private function eventReceived(evt:Event):void{
                 Alert.show("Event received!");  //this is never shown
             }

         ]]>
     </mx:Script>

     <mx:Button id="btn" x="209" y="299" label="Button"
click="btnClicked(event);"/>

</mx:Application>

Reply via email to