Regardless of the intended use of your menu, you define the structure
of the menu as a separate file containing an XML or JSON structure.
Before you can assign a menu in your application, first use the
framework to load and parse the menu structure file. To load and
parse a menu structure file, use one of these two framework methods:
Both methods accept one argument: the file path of the menu structure
file. Both methods load the file from that location. They parse
the file contents and return a NativeMenu object with the menu structure
defined in the file. For example, the following code loads a menu
structure file named “windowMenu.xml” that’s in the same directory
as the HTML file that’s loading it:
var windowMenu = air.ui.Menu.createFromXML("windowMenu.xml");
In the next example, the code loads a menu structure file named “contextMenu.js”
from a directory named “menus”:
var contextMenu = air.ui.Menu.createFromJSON("menus/contextMenu.js");
Note:
The generated NativeMenu object can only be used once as an
application or window menu. However, a generated NativeMenu object
can be used multiple times in an application as a context or icon
menu. Using the MenuBuilder framework on Mac OS X, if the same NativeMenu
is assigned as the application menu and also as another type of
menu, it is only used as the application menu.
For details of the specific menu structure that the MenuBuilder
framework accepts, see
Defining MenuBuilder menu structure
.