To create a NativeMenu object to serve as the root of the menu,
use the NativeMenu constructor:
var root = new air.NativeMenu();
For application and window menus, the root menu represents the
menu bar and should only contain items that open submenus. Context
menu and pop-up menus do not have a menu bar, so the root menu can
contain commands and separator lines as well as submenus.
After the menu is created, you can add menu items. Items appear
in the menu in the order in which they are added, unless you add
the items at a specific index using the
addItemAt()
method
of a menu object.
Assign
the menu as an application, window, or icon menu, or display it
as a pop-up menu, as shown in the following sections:
Setting the application menu or window menu
It’s
important that your code accommodate both application menus (supported on
Mac OS) and window menus (supported on other operating systems)
var root = new air.NativeMenu();
if (air.NativeApplication.supportsMenu)
{
air.NativeApplication.nativeApplication.menu = root;
}
else if (NativeWindow.supportsMenu)
{
nativeWindow.menu = root;
}
Note:
Mac OS defines a menu containing
standard items for every application. Assigning a new NativeMenu
object to the
menu
property of the NativeApplication object
replaces the standard menu. You can also use the standard menu instead
of replacing it.
The
Adobe Flex provides a FlexNativeMenu class for easily creating menus
that work across platforms. If you are using the Flex Framework,
use the FlexNativeMenu classes instead of the NativeMenu class.
Setting a dock icon menu or system tray icon menu
air.NativeApplication.nativeApplication.icon.menu = root;
Note:
Mac OS X defines a standard menu for the application
dock icon. When you assign a new NativeMenu to the menu property
of the DockIcon object, the items in that menu are displayed above
the standard items. You cannot remove, access, or modify the standard
menu items.
Displaying a menu as a pop-up
root.display(window.nativeWindow.stage, x, y);