PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: eco_bach on July 29, 2009, 05:24:48



Title: Using implicit getters in concrete mediators
Post by: eco_bach on July 29, 2009, 05:24:48
p35 of the best practices document
http://puremvc.org/component/option,com_wrapper/Itemid,30/

If I try duplicating the example, using the following in my LoginPanelMediator, loginPanel traces null. Also, shouldn't viewComponent in the implicit getter reference the Main class , passed in thru the body of the StartUpCommand?


//CODE START
// User clicked Login Button; try to log in
private function onTryLogin ( event:Event ) : void {

trace('loginPanel==='+loginPanel);//traces null
sendNotification( ApplicationFacade.LOGIN, loginPanel.loginVO );
}
// Cast the viewComponent to its actual type.
protected function get loginPanel() : LoginPanel {
return viewComponent as LoginPanel;
}

//CODE END


Title: Re: Using implicit getters in concrete mediators
Post by: Neil Manuell on July 30, 2009, 11:59:22
are you using flex?
have you read the slacker tutorial?
http://puremvc.org/content/view/92/1/

the most likely cause of your problem is the deferred instantiation of the flex component you view wraps


Title: Re: Using implicit getters in concrete mediators
Post by: philipSe on July 31, 2009, 02:55:37

Also, shouldn't viewComponent in the implicit getter reference the Main class , passed in thru the body of the StartUpCommand?

The implicit getter would reference Main in the mediator for Main, often named ApplicationMediator.  But for other mediators, the getter references the viewComponent being mediated, in this case viewComponent LoginPanel.  The LoginPanel instance has been passed to the constructor of LoginPanelMediator.
----Philip


Title: Re: Using implicit getters in concrete mediators
Post by: puremvc on July 31, 2009, 04:08:26
Are you sure that you actually passed in a LoginPanel instance when you constructed the Mediator? Try putting a breakpoint (or trace if you prefer) in the constructor:

:
public function LoginPanelMediator( viewComponent:LoginPanel )
{
     super( NAME, viewComponent );
     trace ("in LoginPanelMediator constructor. viewComponent = "+viewComponent);
}

-=Cliff>