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

  1. So what about if you have objects that are being injected that are not being used at the beginning and you want to avoid taking the hit to give yourself the best startup time possible. How would you address handle that situation.
  2. Hi Ron,
    I would recommend you to ask your questions in the forums.

    To answer your question, objects are injected as they are created. If an object is not created because it is not used until for example the user goes to certain screen, then no injection will be performed.

Comments now closed