Mediator not registering in time.

visnik's Avatar

visnik

05 Apr, 2012 07:19 PM

I ran into a bit of an issue where my mediator is being mapped, but not registered in time. Here is what I have going on:

When a user mouses over a button an event is dispatched, my command is being executed. My command creates a Popup (via a helper class), and I manually create the needed mediator (within the helper class). Back to my Command and event is dispatched to said created mediator, but it seems the onRegister for the mediator is running a little to late, here is a sample of my trace statements:

Command Executed
PopUp Window created
mediator created
Dispatching event
calling onRegister

I have tried using mediatorMap.hasMediator() and mediatorMap.hasMediatorForView() to do a check before I dispatch my event, but it seems they both still return true before onRegister had been called. I have tried to manually register my mediator with the mediatorMap.registerMediator(), though this did not seem to work either.

Samples of the code:
my command:
'override public function execute():void

    {
        trace("Command Executed");

         //Some code here

        var popUpWindow:IFlexDisplayObject =  helper.openPopup(ThumbsWindow, mediatorMap);

        //More code here

        trace("Dispatching event");
        //dispatch event that will carry a copy of the screenshot as a payload
        dispatch(new ScreenShotEvent(ScreenShotEvent.SEND_SCREENSHOT, screenShot));
    }'

relevant code from my helper class:

'public function openPopup(viewClass:Class, mediatorMap:IMediatorMap):IFlexDisplayObject

    {
        //Reterive the top level of the application and cast as a display object
        var parent:DisplayObject = FlexGlobals.topLevelApplication as DisplayObject;

        //Create a popup
        var popUpWindow:IFlexDisplayObject = PopUpManager.createPopUp(parent, viewClass, false);
        trace("PopUp Window created");

        mappedMediator = mediatorMap.createMediator(popUpWindow);

        //Return the popup window for later reference
        return popUpWindow;
    }'

Thanks guys.

  1. Support Staff 1 Posted by Ondina D.F. on 06 Apr, 2012 08:48 AM

    Ondina D.F.'s Avatar

    Hi!

    Possible solutions:

    • use Stray’s RelaxedEventMap: https://github.com/Stray/robotlegs-utilities-RelaxedEventMap
    • pass your screenShot to your popup when you create it: access a public method on your popup view
    • let popup’s mediator ask for the screenshot on its onRegister(): dispatch an event to trigger a command …

    Does this help?
    Ondina

  2. Support Staff 2 Posted by Shaun Smith on 06 Apr, 2012 03:56 PM

    Shaun Smith's Avatar

    Hello Visnik,

    When mediating a Flex component, the mediator waits for the creationComplete event before invoking onRegister (if the component is not initialized at the time of mediation):

    https://github.com/robotlegs/robotlegs-framework/blob/master/src/or...

    This explains the behaviour you are seeing. The purpose of that code is to ensure that by the time you enter onRegister you can be sure that the view component is ready to be interacted with.

    You can change that behaviour by overriding preRegister, not calling super, and instead immediately calling onRegister. But, bear in mind that if you do that your UIComponent won't be initialized by the time you start interacting with it and you might run into issues related to that (null pointer exceptions for example).

    Hope that helps.

  3. Ondina D.F. closed this discussion on 05 May, 2012 01:20 PM.

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

Keyboard shortcuts

Generic

? 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