Creating an application or window menu

Adobe AIR 1.0 and later

When you create an application or window menu using the MenuBuilder framework, the top-level objects or nodes in the menu data structure correspond to the items that show up in the menu bar. Items nested inside one of those top-level items define the individual menu commands. Likewise, those menu items can contain other items. In that case the menu item is a submenu rather than a command. When the user selects the menu item it expands its own menu of items.

You use the Menu.setAsMenu() method to set a menu as the application menu or window menu for the window in which the call executes. The setAsMenu() method takes one parameter: the NativeMenu object to use. The following example loads an XML file and sets the generated menu as the application or window menu:

var windowMenu = air.ui.Menu.createFromXML("windowMenu.xml"); 
air.ui.Menu.setAsMenu(windowMenu);

On an operating system that supports window menus, the setAsMenu() call sets the menu as the window menu for the current window (the window that’s represented as window.nativeWindow ). On an operating system that supports an application menu, the menu is used as the application menu.

Mac OS X defines a set of standard menus as the default application menu, with the same set of menu items for every application. These menus include an application menu whose name matches the application name, an Edit menu, and a Window menu. When you assign a NativeMenu object as the application menu by calling the Menu.setAsMenu() method, the items in the NativeMenu are inserted into the standard menu structure between the Edit and Window menus. The standard menus are not modified or replaced.

You can replace the standard menus rather than supplement them if you prefer. To replace the existing menu, pass a second argument with the value true to the setAsMenu() call, as in this example:

air.ui.Menu.setAsMenu(windowMenu, true);

// Ethnio survey code removed