Mediator does not seem to be receiving events

Jim's Avatar

Jim

23 Sep, 2011 01:53 PM

I'm a newbie to robotlegs, switching over from Mate as Mate support is very sporadic these days.

I've set up a very simple application. I have my Context in the Main mxml like so:

<appContext:MainContext contextView="{this}"/>

In the context, I map my views, like so:

override public function startup():void
{

mediatorMap.mapView(MainUI, MainMediator);
mediatorMap.mapView(Login, LoginMediator);
mediatorMap.mapView(newUser, NewUserMediator);
super.startup();

}

In the Main Mediator I register an event listener, like so:

override public function onRegister():void
{

eventMap.mapListener(eventDispatcher, MainEvent.FOCUS, whenFocus, MainEvent);

}

And the view is injected into the mediator.

In the view that is injected into the MainMediator I have a viewstack with a couple of views.

For the LoginMediator which has the Login view injected into it, I have a button that user clicks to change the view. This button fires the MainEvent like so:

dispatchEvent(new MainEvent(MainEvent.FOCUS, 1));

This is supposed to call the whenFocus function in the MainMediator which I registered as a listener. All the startup and onRegister functions are being called as well as the dispatchEvent, but the whenFocus is never being called. I'm sure it's something simple, but I haven't been able to figure it out yet. I tried searching the knowledge base but couldn't find anything to my specific problem. Any help appreciated. Thanks.

  1. 1 Posted by Stray on 23 Sep, 2011 02:04 PM

    Stray's Avatar

    Hi Jim,

    you'll need your LoginMediator to catch the event on it's view, and redispatch it for the whole app to see. Actually this is really just a 'redispatch'.

    The code in onRegister of your LoginMediator would be:

    addViewListener(MainEvent.FOCUS, dispatch, MainEvent);

    'dispatch' is just the function that dispatches an event to the shared eventDispatcher.

    The 3rd param - MainEvent is just to add type safety.

    hth - come back if that's not working for you,

    Stray

  2. 2 Posted by Jim on 23 Sep, 2011 02:25 PM

    Jim's Avatar

    Yep, that did it. Thanks for the quick reply.

  3. Ondina D.F. closed this discussion on 01 Nov, 2011 11:52 AM.

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