Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
override public function execute(note:INotification):void{ var userVO:UserVO = note.getBody() as UserVO; var userMgmtContainer:UserManagementContainer = new UserManagementContainer(); userMgmtContainer.id = 'userMgmtContainer'; userMgmtContainer.userVO = userVO; sendNotification( ApplicationFacade.REMOVE_LOGIN_PANEL ); sendNotification( ApplicationFacade.ADD_USER_MGMT_CTNR, userMgmtContainer );}
override public function listNotificationInterests():Array{ return [ ApplicationFacade.REMOVE_LOGIN_PANEL, ApplicationFacade.ADD_USER_MGMT_CTNR, ... ]}override public function handleNotification( note:INotification ):void{ case ApplicationFacade.REMOVE_LOGIN_PANEL: app.removeChild(loginPanel); break; case ApplicationFacade.ADD_USER_MGMT_CTNR: app.addChild(note.getBody() as UserManagementContainer); break;}private function app():MyApplication{ return viewComponent as MyApplication;}// assuming the login panel is there first and has id loginPanel.private function loginPanel():LoginPanel { return app.loginPanel as LoginPanel;}
//Define Proxy private var _loginProxy : LoginProxy; private var _userProxy : UserProxy; //Define static const for mediator public static const NAME:String = "ApplicationMediator"; public function ApplicationMediator( viewComponent: Login ):void { super ( NAME, viewComponent ); // local reference to the LoginProxy _loginProxy = facade.retrieveProxy(LoginProxy.NAME) as LoginProxy; _userProxy = facade.retrieveProxy(UserProxy.NAME) as UserProxy; facade.registerMediator(new LoginPanelMediator(app.loginPanel)); } override public function listNotificationInterests():Array { return [ ApplicationFacade.LOGIN_SUCCESS, ApplicationFacade.LOGIN_FAILED, ] } override public function handleNotification( note:INotification ):void { switch ( note.getName() ) { case ApplicationFacade.LOGIN_FAILED: break; case ApplicationFacade.LOGIN_SUCCESS: app.appView.removeChildAt(0); var mainAppPanel: MainApp = new MainApp(); app.addChild(mainAppPanel); break; } } private function get app(): Login { return viewComponent as Login; } // assuming the login panel is there first and has id loginPanel. private function get loginPanel(): Login { return app.loginPanel as Login; }
/** * Listens to the login notification retrieving the LoginProxy and does login */ override public function execute(note:INotification):void { var userVO:UserVO = note.getBody() as UserVO; var mainApp:MainApp = new MainApp(); mainApp.id = 'mainAppPanel'; sendNotification( ApplicationFacade.LOGIN_SUCCESS ); sendNotification( ApplicationFacade.ADD_MAIN_APP ); }
//Notifications const names public static const STARTUP_APP:String = "startupApp"; //Login const names public static const LOGIN:String = "login"; public static const LOGIN_SUCCESS:String = "loginSuccess"; public static const LOGIN_FAILED:String = "loginFailed"; //Main const names public static const MAIN_APP:String = "mainApp"; public static const ADD_MAIN_APP:String = "addMainApp"; /** * Singleton ApplicationFacade Factory Method */ public static function getInstance() : ApplicationFacade { if( instance == null) instance = new ApplicationFacade(); return instance as ApplicationFacade; } /** * Start the application */ public function startupApp(app:Login):void { sendNotification(STARTUP_APP, app); } /** * Register Commands with the Controller */ override protected function initializeController( ) : void { super.initializeController(); registerCommand( STARTUP_APP, StartupAppCommand ); registerCommand( LOGIN, LoginCommand ); }
<mx:VBox id="appView"> <loginComp:LoginPanel id="loginPanel" /></mx:VBox>
<mx:Script> <![CDATA[ public function initApp():void { // The following will fail with: // ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller // this.removeChild(loginPanel); // this will work because the loginPanel is really a child of appView this.appView.removeChild(loginPanel); } ]]></mx:Script>
creationComplete="initApp()"
override public function handleNotification( note:INotification ):void{ case ApplicationFacade.REMOVE_LOGIN_PANEL: app.appView.removeChild(loginPanel); break; case ApplicationFacade.ADD_USER_MGMT_CTNR: app.appView.addChild(note.getBody() as UserManagementContainer); break;}