O'Reilly logo

Beginning Adobe® AIR™: Building Applications for the Adobe Integrated Runtime by Rich Tretola

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.2. Context Menus

Context Menus, otherwise known as Ctrl-Click menus on Mac or right-click menus on Windows, are an important part of traditional desktop applications. AIR gives us the ability to add context menus on any object, which extends flash.display.InteractiveObject. This means that not only can you add a context menu to your application windows, but you can also add context menus to almost all of your visible components.

A context menu is of type NativeMenu, thus creating a context menu is the same as creating a NativeMenu, which is also covered in Chapter 12.

To demonstrate how to use context menus, please start by creating a new AIR project within Flex Builder 3 named Chapter10_ContextMenu, which will automatically create the main application file named Chapter10_ContextMenu.mxml. Now add the contents of Listing 10-10 to Chapter10_ContextMenu.mxml file.

If we examine Listing 10-10, you will see that upon creationComplete of the application, the createMainMenu() function is called. Within this function, a NativeMenu object is created, and four NativeMenuItems are also created. The NativeMenuItems are all assigned the same event listener so that when they are selected, the handleMenuClick function is called. This function evaluates the menu item that was selected and then calls the corresponding method on the application to minimize, maximize, restore, or close the application. The results can be seen in Figure 10-7.

The final version of this file can be seen in Listing ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required