The menus you’ve created in that examples so far have all been generated through predefined ActionScript code. If you wanted to change the label of an item on the menu, change the order of the items, or remove or add elements, you would have to recompile the Flash project. You would also have to generate a new installation file for the application, or provide an update, if the application supports updates.
When you’re developing real applications, it’s advisable to create applications that don’t need to be recompiled every time you make minor changes. If your user had to update the whole application (not just a few configuration files) every week or every month, you’d probably lose your audience quite quickly.
To avoid or at least limit these situations, you can extend the NativeMenu class . You can create a class that allows the menu items to be generated dynamically from an XML structure. Because native menus are hierarchal, it’s relatively easy to represent a native menu skeleton to an XML structure. Another advantage is the possibility of changing the localization
of the menu of the application by loading different XML documents.
First, you have to define the structure of the XML document so that each item on the menu is represented by a MenuItem node . The attributes of each node will define the properties to be assigned to the corresponding instance of the NativeMenuItem class that will be created. You can also embed MenuItem nodes in other MenuItem nodes to generate submenus.
A MenuItem node will have the following skeleton:
<MenuItem label="" isSeparator="" mnemonicIndex="" keyEquivalent="" name="" select="" />
The attributes provided allow you to define the structure and behavior of the corresponding menu items. Here is an analysis of the attributes:
label : This is the text label that will be assigned to the element, be it a command
or a submenu.
isSeparator : This is a Boolean value that specifies if the element will be a separator or not. If the value is true, the element will be a separator, so all other attributes will be ignored.
mnemonixIndex : This specifies the index that corresponds to the letter of the text label that is recognized as a shortcut key. You can use this shortcut when you are exploring the items on the menu with the keyboard arrows. This parameter can
only be applied in AIR projects with window and application menus.
keyEquivalent : This specifies the letter that will select an item on the menu when it’s pressed in conjunction with the Ctrl key on Windows or the Cmd key on Mac OS X. In order for this shortcut to work, the application has to be active and in the
foreground. This parameter can only be applied to window and application menus.
name : This is a unique ID that doesn’t depend on the localization of the element.
select : This is the name of the method that has to be called upon a selection
event. This attribute allows you to easily activate, deactivate, or change the functions