| By Marco Casario | RIAvolutionize the web | Article Rating: |
|
| January 19, 2009 09:49 AM EST | Reads: |
664 |
The Essential Guide to Flash CS4 AIR Development book is oriented to Flash developers interested in building desktop applications via Adobe AIR. You can order The Essential Guide to Flash CS4 AIR Development on Amazon or buy it on local bookstore.
This is the fourth part of the series dedicated to AIR menus (Chapter
6 of the Essential Guide to Flash CS4 AIR Development). You can read
the previous articles here:
- Creating AIR submenus for a native menu with Flash CS4 - Part 2 (The Essential Guide to Flash CS4 AIR Development Highlight)
- Creating AIR native menu with Flash CS4 - Part 1 (The Essential Guide to Flash CS4 AIR Development Highlight)
- Using the menuItemSelected() method with Flash CS4
When you interact with a desktop application, you’re used to using general menus that guide you and introduce you to the functions you can choose from. For example, if you’re using a word-processing program and you want to know which formats you can save the document in, you will almost definitely look for the Save as command from the File menu, without even thinking about it. Likewise, if you need to copy the selected text, you’ll look for the Copy command from the Edit menu. These operations are strongly embedded in every user that has experience with modern computers. Regardless of any previous knowledge about the program you’re working on, the menu bar will always be a safe haven where you can look for the commands and functions you need.
Some modern software applications have interfaces that mimic the standards of many web applications. These applications don’t have traditional menus—they only provide icons in the application, and these are sometimes difficult to interpret. When users access one of these programs for the first time, they may feel disoriented, and may not even understand how to start using the application.
AIR puts users at ease by supporting a traditional menu bar that guides them through the features of your application. As mentioned at the beginning of the chapter, there are two types of menus for AIR applications: application menus (on Mac OS X systems) and window menus (on Microsoft Windows systems).
To know which type of menu you can use in your application, AIR provides the supportsMenu property in the NativeApplication class as well as in the NativeWindow class . These are Boolean properties and they show whether the menus are supported at the application or window level. To check if application- level menus are supported, you can use the following code:
If( NativeApplication.supportsMenu == true )
{
// code to manage application menu
}
To check if window menus are supported, you can use the following:
If( NativeWindow.supportsMenu == true )
{
// code to manage windows menu
}
The procedure to create application menus is identical to the procedure for window menus. The only thing that changes is the object you need to assign the menus to and how the end user will use them.
Creating a menu for multiple operating systems
This exercise is intended to show you how to create an application that provides its own menu bar. It’s also intended to show you how to make the menu behave properly on operating systems that require application menus as well as on systems that require window menus.
Start by opening the Flash CS4 ch06p02.fla project . As you can see in Figure 6-5, the stage of your project only contains a TextArea component. Like in the previous exercise, you’ll use it as a console for your messages. These messages keep track of the operations that occur during the execution of your application. The real important part of your application is the menu bar you’ll create with ActionScript code.
Next, access the Ch06p02.as class , which is the document class of the project. Click the Edit class definition icon on the Document Properties panel, as shown in Figure 6-6.
As usual, the class begins by defining its namespace and importing the external classes it depends on:
package com.comtaste.foed.essentialair.chapter6
{
// Flash CS4 specific components classes
import fl.controls.TextArea;
// Adobe AIR and ActionScript classes
import flash.desktop.NativeApplication;
import flash.display.MovieClip;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.display.NativeWindow;
import flash.events.Event;
import flash.filesystem.File;
// class definition
public class Ch06p02 extends MovieClip
{
After the opening declarations of the classes, you set the variables that the whole class can use:
// onstage components
public var output:TextArea;
// class properties
private var menuRoot:NativeMenu;
The output variable represents a reference to the TextArea on the stage of the Flash CS4 project. The menuRoot variable will contain the menu of your application. The constructor method of the class initializes the native menu. It also checks if it has to be assigned to the application or window menu, according to the functions of the local operating system. The following code opens the constructor method:
public function Ch06p02()
{
The constructor method of the class invokes the execution of the super constructor , meaning the constructor method of the class that you’re extending. Then it calls the execution of the createNativeMenu() method , which instantiates and prepares the instance of the NativeMenu class that you’ll use as the application menu. Here’s the code:
// call super constructor function
super();
// generate native menu to use
createNativeMenu();
Once you’ve created the menu, you have to assign it to the application. First, you have to establish whether to associate it with the main window or the application.
Using application menus
To check if you can assign the menu to the application, you have to check the value of the supportsMenu variable of the NativeApplication class . If it’s true, it means that you can use the application- level menus. Then you assign the menuRoot object , which is an instance of the NativeMenu class , to the menu property of the nativeApplication object of the NativeApplication class. Now the application- level menus are only available on Mac OS X operating systems. Here’s the code to accomplish these tasks:
// assign to application menu if we are on Mac OS X
if ( NativeApplication.supportsMenu )
{
NativeApplication.nativeApplication.menu = menuRoot;
}
Using window menus
To check if you can use window menus, you have to test if the value of the supportsMenu property of the NativeWindow class is true. To assign a menu object to a native window, you have to use the menu property of the nativeWindow object of the reference to the stage object owned by the window. The code is as follows:
// assign to window menu if we are on Microsoft Windows
if ( NativeWindow.supportsMenu )
{
stage.nativeWindow.menu = menuRoot; }
}
The constructor method invokes the createNativeMenu() method to instantiate and populate the native menu you are going to work with. This method instantiates an object of the NativeMenu class and assigns it to the menuRoot class variable , which you created previously. To populate the menu, the value returned by the createFirstSubMenu() method — which populates the native menu—is given to the addItem() method of the NativeMenu class as an argument.
// create a complete native menu
private function createNativeMenu():void
{
// instantiate main menu object
menuRoot = new NativeMenu();
// append subMenus to menu root
menuRoot.addItem( createFirstSubMenu() );
}
This is the complete Ch06p02.as class that you have created:
package com.comtaste.foed.essentialair.chapter6
{
import fl.controls.TextArea;
import flash.desktop.NativeApplication;
import flash.display.MovieClip;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.display.NativeWindow;
import flash.events.Event;
import flash.filesystem.File;
public class Ch06p02 extends MovieClip
{
// onstage components
public var output:TextArea;
// class properties
private var menuRoot:NativeMenu;
public function Ch06p02()
{
super();
// generate native menu to use
createNativeMenu();
// assign to application menu if we are on Mac OS X
if ( NativeApplication.supportsMenu )
{
NativeApplication.nativeApplication.menu = menuRoot;
}
// assign to window menu if we are on Microsoft Windows
if ( NativeWindow.supportsMenu )
{
stage.nativeWindow.menu = menuRoot;
}
}
// create a complete native menu
private function createNativeMenu():void
{
// instantiate main menu object
menuRoot = new NativeMenu();
// append subMenus to menu root
menuRoot.addItem( createFirstSubMenu() );
}
}
}
Read the original blog entry...
Published January 19, 2009 Reads 664
Copyright © 2009 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Adobe Flex Developer Earns $100K in New York City
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Ph.D. in Twitter Anyone?
- Eolas Sues the Internet
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Special Report on the Emerging Cloud Computing Trend
- Adobe Cans Another 9% of its Workforce
- My Thoughts on Ulitzer
- Ulitzer.com Named Exclusive "New Media" Sponsor of Cloud Computing Conference & Expo
- Ulitzer Live! New Media Conference & Expo
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Executives Feature on Cloud Computing Expo Power Panel
- Software Flexibility in the Cloud - Part 4 of 5
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- Adobe Unveils LiveCycle Enterprise Suite 2 for Deployment in the Cloud
- Where Are RIA Technologies Headed in 2008?
- Cover Story: How to Increase the Frame Rates of Your Flash Movies
- AJAX World RIA Conference & Expo Kicks Off in New York City
- Your First Adobe Flex Application with a ColdFusion Backend
- Adobe Flex 2: Advanced DataGrid
- i-Technology Blog: Death-Knell For "Rich Media? Hardly!
- Adobe/Macromedia - Microsoft, Look Out!
- How To Create a Photo Slide Show ...
- Adobe Flex Interface Customization - Themes, Styles, Skins
- Personal Branding Checklist
- Has the Technology Bounceback Begun?
- "Real-World Flex" by Adobe's Christophe Coenraets




































