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

Related Topics: Adobe Flex, ColdFusion, Machine Learning

Adobe Flex: Article

Creating Adobe AIR Native Menu with Flash CS4

The Essential Guide to Flash CS4 AIR Development Highlight - Part I

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.

Menus are an integral part of your life as a software user. You find them on the Web, in desktop applications, on your own operating system, and even on mobile devices like cell phones and personal digital assistants (PDAs) . You often don’t realize how important menus are when you use them. It’s so obvious to have them that you only realize how important they are when they aren’t available.

The Essential Guide to Flash CS4 AIR DevelopmentOn the Web, you normally have menus regarding the browser, which allow you to access the content of the site you are using. You rarely have menus that give you access to the specific commands and functions of the website. However, things are changing slowly with the advent of Web 2.0 applications, and menus—not only browsing menus but those specifically related to the web application—are becoming more and more frequent.

As Flash web developers, you have the following options to create menus for your applications:

Adding items to the context menu provided by Flash Player
Creating your own menus

Both options work very well, but the option of using Flash Player’s context menu doesn’t give you much flexibility. The other option requires a substantial amount of time and effort to obtain valid results if you create the menus for your web application from scratch.
When you develop Adobe AIR applications with Flash CS4, you don’t need to worry about how to offer advanced functions with a menu. The framework itself provides various solutions to choose from according to your needs. AIR implements two new classes that aren’t available for Flash Player in a web environment in the flash.display package :

  • NativeMenu
  • NativeMenuItem

These classes allow you to create native system menus to use as application menus (on Mac OS X systems), window menus (on Windows systems), pop- up menus, and context menus. The native menu classes are an addition to the following classes that are already available to create personalized context menus:

  • ContextMenu
  • ContextMenuItem

The native menu classes provide more flexibility than the traditional classes for context menus. This chapter will provide information on the options you have to create menus for your applications. We’ll begin with a tour of the various types of menus that you can use for your AIR applications:

  • Window menus (Microsoft Windows systems)
  • Application menus (Mac OS X systems)
  • System tray and dock icon menus
  • Context menus
  • Pop-up menus

Menus are hierarchical structures: they have a root, and in the case of native menus, they are represented by an instance of the NativeMenu class . A menu is a series of nodes that can be commands or, in turn, menus themselves. Any node is represented by instances of the NativeMenuItem class . When a command is selected, it generates an event, which conveys the information regarding the element of the relevant menu. This event is conveyed as an instance of the flash.events.Event class . Recall that application and window menus can’t contain commands as top- level elements.

Therefore all the instances of the NativeMenuItem class that are top- level nodes contain instances of the NativeMenu class to define the submenus.
It’s possible to associate the following types of information to each instance of the NativeMenuItem class:

  • The name property : A single and unique identification that won’t be displayed
  • The label property : A text label that will be displayed in the menu
  • The data property : An object of any kind, containing information regarding the selected item on the menu

In addition to the selection event, the elements of the menu also generate a display event. The display event is generated a moment before a drop- down menu is rendered by Flash Player. This event allows you to update the content of the menu before it is displayed. You can register the display event both on the instance of the NativeMenu class that contains the menu and one of its items.

A good example of how to use the display event is in a menu that lists the recent web pages that the user has visited. Each time the user accesses the list, the application regenerates the list by checking which pages have been visited lately. It is also possible to use the display event to disable or hide the items on the menu when necessary. You might want to do this if the user doesn’t have the necessary privileges to access some of the functions of your application.

Creating a native menu

When you work on native menus in AIR, you always deal with instances of the NativeMenu class. To create a native menu, start up Flash CS4 and open the AIR ch06p01.fla project . The project has been set up so that it doesn’t automatically declare the variables of the elements on the screen. This option is defined by the Automatically declare stage instances check box in the Advanced ActionScript 3.0 Settings panel, which can be reached through the Publish Settings panel.

Menus are hierarchical structures: they have a root, and in the case of native menus, they are represented by an instance of the NativeMenu class . A menu is a series of nodes that can be commands or, in turn, menus themselves. Any node is represented by instances of the NativeMenuItem class . When a command is selected, it generates an event, which conveys the information regarding the element of the relevant menu. This event is conveyed as an instance of the flash.events.Event class. Recall that application and window menus can’t contain commands as top- level elements.

Therefore all the instances of the NativeMenuItem class that are top- level nodes contain instances of the NativeMenu class to define the submenus.
It’s possible to associate the following types of information to each instance of the NativeMenuItem class:

  • The name property : A single and unique identification that won’t be displayed
  • The label property : A text label that will be displayed in the menu
  • The data property : An object of any kind, containing information regarding the selected item on the menu

In addition to the selection event, the elements of the menu also generate a display event. The display event is generated a moment before a drop- down menu is rendered by Flash Player. This event allows you to update the content of the menu before it is displayed. You can register the display event both on the instance of the NativeMenu class that contains the menu and one of its items.

A good example of how to use the display event is in a menu that lists the recent web pages that the user has visited. Each time the user accesses the list, the application regenerates the list by checking which pages have been visited lately. It is also possible to use the display event to disable or hide the items on the menu when necessary. You might want to do this if the user doesn’t have the necessary privileges to access some of the functions of your application.

Creating a native menu

When you work on native menus in AIR, you always deal with instances of the NativeMenu class. To create a native menu, start up Flash CS4 and open the AIR ch06p01.fla project . The project has been set up so that it doesn’t automatically declare the variables of the elements on the screen. This option is defined by the Automatically declare stage instances check box in the Advanced ActionScript 3.0 Settings panel, which can be reached through the Publish Settings panel .

The class creates a native menu and associates it with the custom menu button with the instance name button as a context menu on the stage. To create a menu object, you have to create an instance of the NativeMenu class, like this:

var menu:NativeMenu = new NativeMenu();

To populate the native menu with some elements, you can use the following addItem() and addSubMenu() functions , which respectively allow you to add commands and submenus to the native menu:

// add a NativeMenuItem to native menu
menu.addItem( new NativeMenuItem( "menu element" ) );
// add a submenu to native menu
menu.addSubMenu( new NativeMenu(), "submenu element" );

Following is the code of the Ch06p01.as class . Notice the details: as you may already know, the class defines the package it belongs to. Then it declares all the classes it has to import to make the ActionScript code work properly:

package com.comtaste.foed.essentialair.chapter6
{
import fl.controls.Button;
import fl.controls.TextArea;
import flash.display.MovieClip;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.events.Event;
import flash.filesystem.File;

Among others, the NativeMenu and NativeMenuItem classes are imported, from the flash. display package, making it possible to create and use the native menus.

The following class declaration shows that you are extending the MovieClip class . This is necessary because the class will be associated with the Flash project and therefore has to define the properties and functions it needs to be rendered by Flash Player.

// class declaration
public class Ch06p01 extends MovieClip
{

Now that the class has been defined, you can declare the variables that the elements of the class can use. The variables have to include all the instances of the objects on the stage that have been assigned an ID. Here’s the code:

// onstage components
public var button:Button;
public var output:TextArea;
// class properties
private var menuRoot:NativeMenu;

The menuRoot variable will contain the native menu that will be associated with the button button . The menu will be created and associated with the button in the constructor method of the class.

The constructor method of a class is a method with the same name as the class. Flash Player executes this method automatically each time an instance of the class is created. That’s why it’s called a constructor method. Its purpose is to allow the initialization of the elements and the functions the class needs to make the class work. This method doesn’t have a return type, as it can’t be used arbitrarily. It can only be launched when the class is instantiated. Also note that the constructor method must be public in ActionScript 3.

Here’s an example of how to use the menuRoot variable :

// class constructor
public function Ch06p01()
{
// call super class constructor
super();
// generate native menu to use
createNativeMenu();
// assign menu to right- click on button
button.contextMenu = menuRoot;
}

Next, launch the createNativeMenu() method in the class constructor. This method is in charge of instantiating and populating the native menu. Then you assign the menuRoot variable, which contains your native menu, to the contextMenu property of the component of the Button class . Assign an instance of a native menu to this property. Doing so tells Flash Player that the relevant menu should be displayed on the button when the user right- clicks (on Windows) or Ctrl- clicks (on the Mac).

To create the native menu, the createNativeMenu() method executes the following instructions:

// create a complete native menu
private function createNativeMenu():void
{

An instance of the NativeMenu class is assigned to the menuRoot variable as follows:

// instantiate main menu object
menuRoot = new NativeMenu();

Then two submenus are added to the native menu you’ve just created. The two following functions have been prepared to generate the submenus:

createFirstSubMenu()

createSecondSubMenu()

These functions are in charge of creating the submenus and returning the instances. Here’s the code:

// append subMenus to menu root
menuRoot.addItem( createFirstSubMenu() );
menuRoot.addItem( createSecondSubMenu() );
}

This is the complete ActionScript class that you have created:

package com.comtaste.foed.essentialair.chapter6
{
import fl.controls.Button;
import fl.controls.TextArea;
import flash.display.MovieClip;
import flash.display.NativeMenu;
import flash.display.NativeMenuItem;
import flash.events.Event;
import flash.filesystem.File;
public class Ch06p01 extends MovieClip
{
// onstage components
public var button:Button;
public var output:TextArea;
// class properties
private var menuRoot:NativeMenu;
public function Ch06p01()
{
super();
// generate native menu to use
createNativeMenu();
// assign menu to right- click on button
button.contextMenu = 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() );
menuRoot.addItem( createSecondSubMenu() );
}
}
}

In the second part of The Essential Guide to Flash CS4 AIR Development Highlight you'll learn how to create a submenu item, using the NativeMenuItem class.

The original article is published on Marco Casario's blog : Creating AIR native menu with Flash CS4 - Part 1 (The Essential Guide to Flash CS4 AIR Development Highlight)

More Stories By Marco Casario

Marco Casario is CEO of Comtaste, a company devoted to develop Rich Internet Applications on the Web and for mobile devices.

He collaborates intensively with Adobe Italy as a speaker at conferences and as a consultant for Flash, Flex, and Flash Lite.

Learn more about Marco Casario at his blog http://casario.blogs.com. In 2005, Marco has founded Comtaste, a company dedicated to exploring new frontiers in Rich Internet Applications and the convergence between the web and the world of mobile devices — MobyMobile and YouThru are representative of their recent work. He is founder of the biggest worldwide Flash Lite User Group and of www.augitaly.com, a reference point for the Italian community of Adobe users, in which he carries out the role of Channel Manager for the section dedicated to Flex.

@ThingsExpo Stories
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.