tab navigator deferred instantiation issue

Joel's Avatar


03 May, 2010 02:49 PM

I have an application I am currently working that I'm creating view states to switch between login screen, job selection and ordering, the states are working fine. For job selection, I need to allow users to select different methods of searching through a tabnavigator.

I'm trying to write it where the separate tabs are each a different view with a mediator attached to each. so I have a tab navigator element, inside that are S:NavigatorContent elements, and the actual views are children of those NagivatorContent elements.

I've got the mediators mapped, but they don't seem to exist when I run the application. The views are created as needed, and the init method is ran on the view I'm working on, but the mediator isn't catching an event that is dispatched in the view to pass up to the controller.

Is there something strange I have to do with robotlegs to insure the mediators are instantiated correctly when using tab navigators and dealing with deferred instantiation?

  1. 1 Posted by Joel on 03 May, 2010 03:35 PM

    Joel's Avatar

    I may have just answered my own question, it seems like when dealing with a view that was deferred, the mediator maps the listeners correctly when you override the preRegister event instead of the onRegister event.

    If this is wrong and there is a better method or best practice I am ignoring, please let me know.

  2. Support Staff 2 Posted by Shaun Smith on 03 May, 2010 06:29 PM

    Shaun Smith's Avatar

    Hi Joel,

    When a MediatorMap creates and registers a Mediator it calls preRegister - it then becomes the mediator's responsibility to call the onRegister hook on itself when it has decided that the view component is ready:

    In the case of Flex components, onRegister is only called after CREATION_COMPLETE has fired. This design is intended to ease deferred instantiation issues - you can be sure that your view component is actually ready before you manipulate it through the mediator.

    In your case it seems that you need access to the view components before they are actually ready, in which case, overriding preRegister is an acceptable work-around (but be sure to call super.preRegister), though it does lead me to question your current design.. do you really need to have access to those view components immediately? Robotlegs is designed to be lazy: the code you put in onRegister for a particular NavigatorContent only runs when the user actually navigates to that content.

  3. 3 Posted by Joel on 04 May, 2010 01:09 PM

    Joel's Avatar

    Thanks Shaun, that's a great explanation of the sequence of events that happens for deferred instantiation components.

    On the current design, I'm not attempting to really access those views prior to creation, I typically have been putting event listeners into the mediators to listen for events from the view and let them get dispatched by the eventDispatcher from the mediator. This wasn't working properly on those mediators tied to elements in the tabNavigator.

    The issue came to my attention because one of the tabNavigator tabs has a series of progressive drop down lists, countries, states, cities, etc to perform a search, so we needed to load the countries first, then have the events fire down to get states etc.

    good call on the super.preRegister, I'll be sure to add that.


  4. Stray closed this discussion on 10 Feb, 2011 05:07 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac