Oscar
|
|
« on: April 23, 2008, 02:36:37 » |
|
Hi,
just a generally question. Let's say we have this simple Application:
ApplicationFacade Class:
//...............
public function startup(app:App):void { sendNotification(STARTUP, app); } // Register Commands with the Controller override protected function initializeController():void { super.initializeController(); registerCommand(STARTUP, StartupCommand); }
//..................
StartupCommand Class:
//.........
override public function execute(notification:INotification):void { var app:App = notification.getBody() as App; var mediatorName:String = AppMediator.NAME; facade.registerMediator(new AppMediator(mediatorName, app)); }
//.......
AppMediator Class:
//....... override public function handleNotification(note:INotification):void { switch(note.getName()) { case ApplicationFacade.STARTUP: trace("AppMediator recivied the STARTUP EVENT"); break; } } override public function listNotificationInterests():Array { return [ ApplicationFacade.STARTUP ]; }
//.......
App Class
//........
public function App() { var facade:ApplicationFacade = ApplicationFacade.getInstance(); facade.startup(this); }
//.........
Like you can see, the AppMediator listening for the STARTUP Event. When you start this Application he also received this Event. Exactly this makes me curios. Let's take a look at the start order:
1.) "App" initializes the ApplicationFacade and call the startup function. 2.) The ApplicationFacade sends a STARTUP Event. 3.) Because the Controller listens for this Event, he create/start the "StartupCommand". 4.) This Command create the "AppMediator" ...
At Point 2 the STARTUP Event is throwing. At this Point the "AppMediator" doesn't exist. Only now at Point 4, the Command creates the Mediator.
So, why the "AppMediator" actually received the STARTUP Event?
|