LocalEventMap

The LocalEventMap tag has the same functionality and inner tags as the EventMap tag. The main difference is that the LocalEventMap will only listen to events dispatched by a given dispatcher (unless specified otherwise in the EventHandlers tags). Therefore, when using this tag, you need to specify the event dispatcher to which the event map will add event listeners.

The best application for a LocalEventMap is when you use modules. If, for some reason, you wanted to have an event map that handled events coming from the module only (while ignoring events of the same type dispatched elsewhere), then you can create a LocalEventMap, and include in your module. Please note that you can use the LocalEventMap anywhere, not just in modules, and this is only a usage example:

<mx:Module ...>
   <maps:MyLocalEventMap dispatcher="{this}" />
</mx:Module>

Then you create the LocalEventMap in a file called MyLocalEventMap.mxml, extending from LocalEventMap:

<LocalEventMap xmlns="http://mate.asfusion.com/">

   <EventHandlers type="myEventType">
      ... here what you want to happen when this event is dispatched...
   </EventHandlers>
   
   <EventHandlers type="myOtherEventType">
      ... here what you want to happen when this other event is dispatched...
   </EventHandlers>
   
</LocalEventMap>

4 responses

  1. Another great advantage of the local event map that needs pointing out is the fact that it provides another (i.e. local) scope for object instances, as compared to the global scope of the main event map.

    A very good usage example of this is given in the official Mate examples, look for the "documentbased" project. Have a look at the DocumentView.mxml file and function createOpenedDocuments() in MainView.mxml
  2. I want to create a service to be shared by multiple instances of the same class ( possiblly multiple classes). I don't have problem to have events propagated to the service's local event map, I could figure out the best way to get the result back to the consumber side. I tried inject event listener into the consumer class, but the specified method is not called. What's possibly missed?&amp;lt;br /&amp;gt;By the way, when I'm interogating event dispatching, I wanted to distingush instances by something like Java hashcode, I can see them in Flex debugger, how can I get it from AS program?&amp;lt;br /&amp;gt;Thanks in advance.
  3. I meant that I could NOT figure out the best way to get the result back to the consumber side.
  4. Is there any way for setting a dispatcher tag inside LocalEventMap to not just visual element but to specific class? In this moment i've got PresentationModel class that is dispatching specific events and i want them to be listened only by specific LocalEventMap. In my case they are not catched by my map.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;The only way i could figure this to work is by placing another regular Map on my visual element. (or meaby this is the proper way to do this ?)&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;p.s by visual element i mean MXML components

Comments now closed