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: getting 1009 error from mediator  (Read 16280 times)
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« on: April 15, 2011, 12:45:02 »

I've got a mediator that accesses a view component child of the main program.  When I try to set a property of a child view component of the child in that mediator, it get a #1009 error (cannot access null value

   case AuthProxy.AUTH_SUCCESS:
               authVO = note.getBody() as AuthVO;
               contactsControlBar.authLbl.text = authVO.getUserRole;
                contactsControlBar.uNameLbl.text = authVO.getUserName;
            break;

I've searched all over, and I'm pretty sure it has to do with the child component not being instantiated, but I can't really figure out how to implement the fix correctly. One post I read said to use :

override protected function commitProperties():void
20               {
21                   super.commitProperties();
22    }

but I'm still not able to really figure it out. I need to know exactly what's happening, and how the fix works. TIA

Mike
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: April 17, 2011, 10:44:36 »

At least the in the context of what you've posted here, the 'fix' is irrelevant voodoo, ignore it.

Are you using an IDE with a debugger such as Flex/FlashBuilder?

If so, set a breakpoint on this line:
              authVO = note.getBody() as AuthVO;

Now run your app in debug mode and navigate to the point that this breakpoint is hit.

Is the note body null? (in the variables view, inspect note and see what's in the body property) If so, there's your problem. The AuthProxy didn't include the AuthVO in the note.

If not, then inspect the contactsControlBar property. Is it null? If so, there's your problem. Can't say why you've fetched aground here with a mediator that doesn't have a live view component yet, but I suspect your startup sequence could have something to do with it, or Flex's deferred instantiation might as well.

If contactsControlBar does exist, do its children authLbl and uNameLbl exist? Again, couldn't say why they wouldn't be there, but you're being to intrusive with the Mediator here anyway.

Encapsulate the implementation of the view component so that changes to it don't require the Mediator to be refactored. You should have a method on ContactsControlBar that accepts an AuthVO like this:

:
public function setAuthVO( avo:AuthVO ):void
{
   authLbl.text = authVO.getUserRole;
   uNameLbl.text = authVO.getUserName;
}


And inside the Mediator:

:
  case AuthProxy.AUTH_SUCCESS:
            contactsControlBar.setAuthVO  (AuthVO( note.getBody() );
            break;

-=Cliff>
« Last Edit: April 17, 2011, 10:46:43 by puremvc » Logged
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« Reply #2 on: April 28, 2011, 10:25:16 »

Cliff:

I'm using flash builder 4, and I've checked the value of the note body. It's returning the correct values, so I'm pretty sure it has to do with the component not being instantiated. The startup script creates the views and models before it runs the auth command, but is it possible the flex application isn't creating the components before that? if so, what can I do about it?

I'll take your advice about encapsulating the view component. I thought I might using the mediator incorrectly.

Thanks.
Logged
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« Reply #3 on: April 28, 2011, 02:43:47 »

It almost certainly is a problem with the ControlBar component not being instantiated. When I look at the web page for the app, it shows the progress bar being full, but then it throws the error in the debugger before I can see the app itself. the progression for the command is as follows:  facade.startup(this) called from CreationComplete on main program, Startup command is registered to listen for STARTUP notification in ApplicationFacade, AuthCommand is called from StartupCommand, AuthCommand creates authVO, calls authVO method to get username, calls authproxy method to get userRole from remoteObject, authProxy sends notification and authVO with username and userRole as note body to observer, ControlBar mediator listens for notification and then populates labels with values from authVO.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: April 29, 2011, 04:16:44 »

Are you starting up your PureMVC apparatus from the creationComplete handler of your app? If so, try moving it to applicationComplete.

Historically, creationComplete used to be when everything was ready in the application - the end of the mxml creation process. But now there's a subsequent applicationComplete event.

-=Cliff>


Logged
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« Reply #5 on: April 30, 2011, 11:04:19 »

Still bombs out on this line:

contactsControlBar.setAuthVO( AuthVO(note.getBody()) );

I'm stumped.

Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: May 02, 2011, 08:01:51 »

Deferred instantiation, perhaps? Is this component created inside a ViewStack, TabNavigator or other component that defers the creation of its children by default?

Or is this component or its parent created dynamically and injected into the display list via addChild at some point?

How exactly does the mediator come by its reference to the control bar component?

-=Cliff>
Logged
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« Reply #7 on: May 02, 2011, 10:34:46 »

The contactsControlBar is a view component inside the main application file (Contacts.mxml), not in any viewstack or tabnavigator.  The reference to the control bar is in the mediator using a getter:

protected function get contactsControlBar():ContactsControlBar
      {
         return viewComponent as ContactsControlBar;
      }

Am I doing this correctly?
Logged
Mike Zierten
Newbie
*
Posts: 6


View Profile Email
« Reply #8 on: May 02, 2011, 03:27:16 »

It works. After much gnashing of teeth and pulling of hair, I think I finally understand what I did wrong:

ApplicationMediator.as was missing the following getter:

protected function get app():Contacts {
     return viewComponent as Contacts;
}

I just need to figure out what I need for the MainView mediator to register the sub-component mediators properly

Cliff, thanks for all your time and help.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #9 on: May 06, 2011, 08:13:58 »

No problem. Glad you were able to get to the bottom of it.

Cheers,
-=Cliff>
Logged
Pages: [1]
Print