skasssam
|
|
« on: May 28, 2008, 11:50:33 » |
|
I am finally starting to get my application off the ground. I am still trying to wrap my heard around all this since I am new to puremvc and flex.
I am authenticating a user using a remoteobject.
All that works, I am able to authenticate and change my viewstack if the authentication is successful.
On my view that is displayed after the user logs in I want to display a simple "Welcome, <username>"
How do I access my user object from an arbitrary view?
Here is my code for the loginProxy:
public class LoginProxy extends Proxy implements IProxy { public static const NAME:String = "LoginProxy"; private var loginService:RemoteObject; public function LoginProxy( data:Object = null ){ super(NAME, data); } public function userLogin(username:String,password:String):void { loginService = new RemoteObject(); loginService.source = "org.enohp.app.Userdao"; loginService.destination = "userService"; loginService.addEventListener( FaultEvent.FAULT, onFault ); loginService.getUserFromLogin.addEventListener( ResultEvent.RESULT, onResult ); loginService.getUserFromLogin.send(username,password); } private function onResult( event:ResultEvent ):void { if (!event.result) { Alert.show("You have entered an invalid username/password", "Login Error"); } else { setData(event.result as User); Alert.show("You have successfully logged in.", "Login Success"); sendNotification( ApplicationFacade.VIEW_FBAPP ); } } private function onFault(fault:FaultEvent):void { Alert.show(fault.fault.faultString + "\n" + fault.fault.faultDetail, fault.fault.faultCode.toString()); } public function get user():User { return data as User; } }
The loginProxy is called from a notification that is handled by my loginMediator:
private function onMouseClick(e:Event):void { loginProxy.userLogin(theView.username.text,theView.password.text); Alert.show(ObjectUtil.toString(loginProxy.getData()), "Login User from Login Mediator"); }
I thought that my alert in the mediator should show the user that was authenticated but it returns null.
Any help is appreciated.
TIA, Shinan
|