Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: error 1009, viewstack  (Read 6648 times)
dierre
Jr. Member
**
Posts: 11


View Profile Email
« on: December 29, 2008, 06:26:40 »

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.
Logged
dierre
Jr. Member
**
Posts: 11


View Profile Email
« Reply #1 on: December 29, 2008, 06:35:07 »

Ok, I don't why but as soon as I write help 3ds I found a solution -_-
I added creationPolicy="all" to the viewStack component. Is the a correct way to solve the problem?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: December 30, 2008, 06:23:23 »

Have a look in the 'News' section of the site for the article about Slacker, the deferred instantiation demo. This article will inform you about the problem if you don't understand deferred instantiation. Then have a look at the Slacker demo to see how its handled.

-=Cliff>
Logged
dierre
Jr. Member
**
Posts: 11


View Profile Email
« Reply #3 on: January 01, 2009, 11:28:01 »

thanks.
Logged
Pages: [1]
Print