PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: sasuke on May 01, 2010, 01:32:40



Title: Mediator registration for viewstack views
Post by: sasuke on May 01, 2010, 01:32:40
Hi,

My module which has a facade of its own (ModuleFacade) looks something like this:

:
<mx:Module>
  <mx:ViewStack creationPolicy="auto">
    <mx:View1 />
    <mx:View2 />
  </mx:ViewStack>
</mx:Module>

The page loads, the facade is kicked in action, the module mediator is registered, the module mediator receives the confirmation, another command is fired to register the View1, the mediator for view1 is registered and the control reaches the view1 mediator from the registration command. All this works fine. The problem comes when the user switches view. Since the creation policy of my view stack is auto (can't create all views at once), the view2 mediator registration happens before the view2 has been completely created and this results in an error when I try to access my view2 components after the startup command for the view2 completes.

I can attach a creationComplete event listener to the view2 and make the listener function look up the facade, send the notification to the module mediator which in turn would pick up view2 and send it for registration. But this doesn't seem like a very good approach, I mean referring/lookingup facade in each and every view instead of just the main view. Is there any other approach I can use to tackle this problem or is this the only choice?

TIA,
sasuke


Title: Re: Mediator registration for viewstack views
Post by: puremvc on May 03, 2010, 01:18:41
Have a look at the FAQ entry for deferred instantiation. http://puremvc.org/content/view/91/188/

The Slacker demo shows one way of handling this: http://trac.puremvc.org/Demo_AS3_Flex_Slacker

-=Cliff>


Title: Re: Mediator registration for viewstack views
Post by: sasuke on May 04, 2010, 10:50:26
The demo looks interesting, thanks. :)