12.3. Native Menus

AIR has the ability to integrate into the operating system's menu system through the use of its Native Menu API. The NativeMenu object consists of one or many NativeMenuItems and can include dividers and keyboard shortcuts.

12.3.1. Basic NativeMenu

To demonstrate this, let's start by creating a new AIR application named Chapter12_NativeMenu, which will create the main application file of Chapter12_NativeMenu.mxml. Listing 12-25 will show the completed version of Chapter12_NativeMenu.mxml. Please note that this example will only work on the Mac OS X operating system, as Windows does not support native menus on the root application window. For information on how to add native menus to NativeWindows, please refer to Chapter 9.

Since NativeMenu and NativeMenuItem are members of the flash.display package, there are no imports needed to add NativeMenus. However, we will use the Alert class, so please add the script block from Listing 12-19 into the Chapter12_NativeMenu.mxml file.

Example 12-19. The needed import statement
<mx:Script>
  <![CDATA[
   import mx.controls.Alert;
  ]]>
</mx:Script>

Now let's add a simple NativeMenu to the application. First add creationComplete="init()" to the <mx:WindowedApplication> root tag. The code in Listing 12-20 will create a simple menu on creationComplete of the application. It first creates a NativeMenu object named nativeMenu and then a NativeMenuItem object named menuItem with the label "My Menu". It then sets the nativeMenu to ...

Get Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.