Where should the Event Map go?

Typically, the Event Map is a standalone mxml file, although it can be placed inside any other mxml file. When the Event Map is a standalone file, any namespace used inside must be added. Inside the event map, we have the default namespace to be the mate the namespace so that we don't have to prefix the tags with the namespace.

<EventMap>
...event handler lists here...
</EventMap>

The best place to put the event map is in the Application file. This is due to the component creation cycle that Flex follows. If you place your event map deep inside your application, it may not be instantiated early enough to listen to all the events. Placing it in the Application file also allows you to be able to listen to early Flex events such as FlexEvent.PREINITIALIZE.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
      xmlns:maps="com.yourdomain.maps.*">

   
   <maps:MyEventMap />
   
   ...other application components here...

</mx:Application>

2 responses so far

Leave a response

If you need help or want to comment on something not related to this page, please post in the forums. Thanks!

Leave this field empty