Hi, I'm developing a little project but I have some problem. This application starts with a login view.
The main file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:view="view.components.*" pageTitle="Tesi"
horizontalAlign="center" verticalAlign="middle"
creationComplete="facade.startup(this);" >
<mx:Script>
<![CDATA[
import ApplicationFacade;
private var facade: ApplicationFacade = ApplicationFacade.getInstance();
]]>
</mx:Script>
<mx:Panel width="900" height="500" title="TESI" id="tesi" >
<mx:ViewStack id="appView" width="100%" height="100%" >
<view:Login id="login" />
<view:UserProfile id="userprofile" />
</mx:ViewStack>
</mx:Panel>
</mx:Application>
The main idea is: the user logs in and then the application loads the user data in "userprofile"
It's not working because after logs in (and that's fine) the UserProxy.login function send a notification to the application mediator to switch the view (the procedure is the same used in the login demo:
http://puremvc.org/pages/demos/AS3/Demo_AS3_Flex_WebORB_Login/srcview/ ) and send a notification to the UserProfileMediator so the mediator can assign the user information to the component.
UserProfileMediator
package view
{
import model.UserProxy;
import model.vo.User;
import mx.controls.Alert;
import org.puremvc.as3.interfaces.IMediator;
import org.puremvc.as3.interfaces.INotification;
import org.puremvc.as3.patterns.mediator.Mediator;
import view.components.UserProfile;
public class UserProfileMediator extends Mediator implements IMediator
{
public static const NAME:String = "UserProfileMediator";
private var _uproxy: UserProxy;
public function UserProfileMediator( viewComponent:UserProfile )
{
super( NAME, viewComponent );
_uproxy = facade.retrieveProxy( UserProxy.NAME ) as UserProxy;
}
override public function listNotificationInterests():Array
{
return [
UserProxy.LOGIN_SUCCEDED
];
}
override public function handleNotification(notification:INotification):void
{
switch(notification.getName())
{
case UserProxy.LOGIN_SUCCEDED:
userprofile._us = _uproxy.users[0] as User; // TypeError: Error #1009: Cannot access a property or method of a null object reference.
break;
default:
}
}
protected function get userprofile():UserProfile
{
return viewComponent as UserProfile;
}
}
}
Here's the error.
And then the UserProfile.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:help="view.components.*"
width="100%" height="100%" borderStyle="solid">
<mx:Script>
<![CDATA[
import model.vo.User;
[Bindable] public var _us: User;
]]>
</mx:Script>
<mx:Label text="{_us.username}" />
</mx:HBox>
Can you help me? I don't know what I'm doing wrong. The "proxy" part is working, the user infos are loaded.