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
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.
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...
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...
Whenever a new technology hits the high points of hype, everyone starts talking about it like it will solve all their business problems. Blockchain is one of those technologies. According to Gartner's latest report on the hype cycle of emerging technologies, blockchain has just passed the peak of their hype cycle curve. If you read the news articles about it, one would think it has taken over the technology world. No disruptive technology is without its challenges and potential impediments t...
If a machine can invent, does this mean the end of the patent system as we know it? The patent system, both in the US and Europe, allows companies to protect their inventions and helps foster innovation. However, Artificial Intelligence (AI) could be set to disrupt the patent system as we know it. This talk will examine how AI may change the patent landscape in the years to come. Furthermore, ways in which companies can best protect their AI related inventions will be examined from both a US and...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
Bill Schmarzo, Tech Chair of "Big Data | Analytics" of upcoming CloudEXPO | DXWorldEXPO New York (November 12-13, 2018, New York City) today announced the outline and schedule of the track. "The track has been designed in experience/degree order," said Schmarzo. "So, that folks who attend the entire track can leave the conference with some of the skills necessary to get their work done when they get back to their offices. It actually ties back to some work that I'm doing at the University of San...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Dynatrace is an application performance management software company with products for the information technology departments and digital business owners of medium and large businesses. Building the Future of Monitoring with Artificial Intelligence. Today we can collect lots and lots of performance data. We build beautiful dashboards and even have fancy query languages to access and transform the data. Still performance data is a secret language only a couple of people understand. The more busine...