Welcome!

You will be redirected in 30 seconds or close now.

ColdFusion Authors: Yakov Fain, Jeremy Geelan, Maureen O'Gara, Nancy Y. Nee, Tad Anderson

RSS Feed Item

Working with AIR Application and Window menus (The Essential Guide to Flash CS4 AIR Development Highlight)

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:


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...

IoT & Smart Cities Stories
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Early Bird Registration Discount Expires on August 31, 2018 Conference Registration Link ▸ HERE. Pick from all 200 sessions in all 10 tracks, plus 22 Keynotes & General Sessions! Lunch is served two days. EXPIRES AUGUST 31, 2018. Ticket prices: ($1,295-Aug 31) ($1,495-Oct 31) ($1,995-Nov 12) ($2,500-Walk-in)
According to Forrester Research, every business will become either a digital predator or digital prey by 2020. To avoid demise, organizations must rapidly create new sources of value in their end-to-end customer experiences. True digital predators also must break down information and process silos and extend digital transformation initiatives to empower employees with the digital resources needed to win, serve, and retain customers.
IoT is rapidly becoming mainstream as more and more investments are made into the platforms and technology. As this movement continues to expand and gain momentum it creates a massive wall of noise that can be difficult to sift through. Unfortunately, this inevitably makes IoT less approachable for people to get started with and can hamper efforts to integrate this key technology into your own portfolio. There are so many connected products already in place today with many hundreds more on the h...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereal. Andrew's role at ConsenSys Enterprise is a mul...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relationships. And when the cloud is combined with the power of cognitive computing, it drives innovation and transformation that achieves astounding competitive advantage.
Nicolas Fierro is CEO of MIMIR Blockchain Solutions. He is a programmer, technologist, and operations dev who has worked with Ethereum and blockchain since 2014. His knowledge in blockchain dates to when he performed dev ops services to the Ethereum Foundation as one the privileged few developers to work with the original core team in Switzerland.