Exposing menu items to ActionScript

You can assign each menu item a unique identifier in the instanceName attribute, which makes the menu item accessible directly from the root menu. For example, the following XML code provides instanceName attributes for each menu item:

<menu>
    <menuitem label="Item 1" instanceName="item_1" />
    <menuitem label="Item 2" instanceName="item_2" >
      <menuitem label="SubItem A" instanceName="sub_item_A" />
      <menuitem label="SubItem B" instanceName="sub_item_B" />
    </menuitem>
</menu>

You can use ActionScript to access the corresponding instances and their attributes directly from the menu component, as follows:

var aMenuItem = myMenu.item_1;
myMenu.setMenuItemEnabled(item_2, true);
var aLabel = myMenu.sub_item_A.attributes.label;

NOTE

Each instanceName attribute must be unique within the scope of the root menu component instance (including all of the submenus of root).