22 Aug in flex, mate

I've been using Mate heavily over the last few weeks and am really enjoying implementing the architecture. However there are a few gotchas that caught me out and I'll write about them here.
The first is with the way that the EventMap listens for events. One of my data adapters was happily firing dispatchEvent but the EventMap was never handling it. However, if I fired the same event from my main application MXML file, all worked perfectly.
After some choice words I finally figured it out. Mate's EventMap actually listens for events on Application.application. My data adapter was instantiated by Mate and the event was never getting to the Application level.
The easy fix is to dispatch the event directly from Application.application:
Application.application.dispatchEvent(myEvent);
Hope that helps someone!!

Comments

Another, cleaner IMO, way to

Another, cleaner IMO, way to do this is to create a Dispatcher:

var dispatcher:Dispatcher = new Dispatcher();
dispatcher.dispatchEvent(myEvent);

- Steven

Recently stumbled into this.

Recently stumbled into this. The cafe townsend example on the Mate site shows a cleaner way (IMHO) to tackle this, by passing a reference to the eventMap dispatcher to your data adapter. That way the event definitely gets to the eventMap. See:

http://mate.asfusion.com/assets/content/examples/cafeTownsend/srcview/

In MainEventMap.mxml

<EventHandlers type="{FlexEvent.PREINITIALIZE}">
        <ObjectBuilder generator="{AuthorizationManager}" constructorArguments="{scope.dispatcher}" />
    </EventHandlers>

Then the dispatcher is used accordingly to fire your events off.

Hope that's of some use.

All content © 2009-2011 Matthew Butt. All views expressed herein are my own and do not represent the views of my employer, AREA203 Digital.