Creating an icon context menu

Adobe AIR 1.0 and later

In addition to context menus for DOM elements within an application window, an Adobe AIR application supports two other special context menus: dock icon menus for operating systems that support a dock, and system tray icon menus for operating systems that use a system tray. To set either of these menus, you first create a NativeMenu using the Menu.createFromXML() or Menu.createFromJSON() method. Then you assign the NativeMenu as the dock or system tray icon menu by calling the Menu.setAsIconMenu() method.

This method accepts two arguments. The first argument, which is required, is the NativeMenu to use as the icon menu. The second argument is an Array containing strings that are file paths to images to use as the icon, or BitmapData objects containing image data for the icon. This argument is required unless default icons are specified in the application.xml file. If default icons are specified in the application.xml file, those icons are used by default for the system tray icon.

The following example demonstrates loading menu data and assigning the menu as the dock or system tray icon context menu:

// Assumes that icons are specified in the application.xml file. 
// Otherwise the icons would need to be specified using a second 
// parameter to the setAsIconMenu() function. 
var iconMenu = air.ui.Menu.createFromXML("iconMenu.xml"); 
air.ui.Menu.setAsIconMenu(iconMenu);
Note: Mac OS X defines a standard context menu for the application dock icon. When you assign a menu as the dock icon context menu, the items in the menu are displayed above the standard OS menu items. You cannot remove, access, or modify the standard menu items.

// Ethnio survey code removed