Comments
yourfanat wrote: I am using another tool for Oracle developers - dbForge Studio for Oracle. This IDE has lots of usefull features, among them: oracle designer, code competion and formatter, query builder, debugger, profiler, erxport/import, reports and many others. The latest version supports Oracle 12C. More information here.
Cloud Expo on Google News
SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Menu Interaction in Adobe AIR
Using the menuItemSelected() method with Flash CS4

The Essential Guide to Flash CS4 AIR Development book is oriented to Flash developers interested in building desktop applications via Adobe AIR. You can preorder it on Amazon or buy it on local bookstore starting from 22nd December.

This is the thrid 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:

Part One - Creating AIR submenus for a native menu with Flash CS4 - Part 2 (The Essential Guide to Flash CS4 AIR Development Highlight

Part Two - Creating AIR native menu with Flash CS4 - Part 1 (The Essential Guide to Flash CS4 AIR Development Highlight

Next, you’ll employ the menuItemSelected() method , which will be launched each time the user selects one of the items on the context menu. When a selection event is generated, the event listener method receives an instance of the flash.events.Event class as an argument. The selection events are transmitted by the selected element on the menu, through the hierarchical structure of the menu, to the root element.
The object received as an argument has the two following properties:

  • target
  • currentTarget

If the event has been registered directly on the elements of the menu (like in this case), the two properties will have the same value. In this case, both properties refer to the instance of the selected NativeMenuItem class . However, if the event is registered on the root menu or on one of the roots of the submenus, the target property of the received event object will always refer to the selected element. The currentTarget property will always refer to the object the event is registered on.

When an item is selected, the menuItemSelected() method writes the label of the selected element in the TextArea, which acts as a text output console. Here’s the code:

// called on click on menu items
private function menuItemSelected( evt : Event ):void
{
// access NativeMenuItem instance selected
var item:NativeMenuItem = evt.target as NativeMenuItem;
// write in the textarea selected item's label
output.appendText( "CLICKED ON: " + item.label + File.lineEnding );
}

Displaying the code for the native submenus

This is the complete Ch06p01.as class that handles with the menuItemSelected() method:

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() );
}
private function createFirstSubMenu():NativeMenuItem
{
// create first submenu
var subMenu:NativeMenuItem =
new NativeMenuItem( "My first custom submenu" );
// initialize child container
subMenu.submenu = new NativeMenu();
// create first submenu child
var subMenuItem1:NativeMenuItem =
new NativeMenuItem( "menu 1 item 1" );
// register event listener for menu item
subMenuItem1.addEventListener( Event.SELECT,
menuItemSelected );
// add item to submenu
subMenu.submenu.addItem( subMenuItem1 );
// create a second child, register event listener for
// selection event and assign to submenu
var subMenuItem2:NativeMenuItem =
new NativeMenuItem( "menu 1 item 2" );
subMenuItem2.addEventListener( Event.SELECT,
menuItemSelected );
subMenu.submenu.addItem( subMenuItem2 );
return subMenu;
}

private function createSecondSubMenu():NativeMenuItem
{
// create first submenu
var subMenu:NativeMenuItem =
new NativeMenuItem( "Second submenu" );
// initialize child container
subMenu.submenu = new NativeMenu();
// create first submenu child
var subMenuItem1:NativeMenuItem =
new NativeMenuItem( "menu 2 item 1" );
// register event listener for menu item
subMenuItem1.addEventListener( Event.SELECT,
menuItemSelected );
// add item to submenu
subMenu.submenu.addItem( subMenuItem1 );
// add a separator item
// label will be ignored for separator items
var subMenuSeparator:NativeMenuItem =
new NativeMenuItem( "", true );
// add separator to menu
subMenu.submenu.addItem( subMenuSeparator );
// create a second child, register event listener for
// selection event and assign to submenu
var subMenuItem2:NativeMenuItem =
new NativeMenuItem( "menu 2 item 2" );
subMenuItem2.addEventListener( Event.SELECT,
menuItemSelected );
subMenu.submenu.addItem( subMenuItem2 );
// create a new item as an internal submenu
// using addSubmenu command
var childSubMenu:NativeMenuItem =
subMenu.submenu.addSubmenu( new NativeMenu(),
"Nested menu" );

// initialize child container
childSubMenu.submenu = new NativeMenu();

// create a child, register event listener for
// selection event and assign to internal submenu

var subMenuItem3:NativeMenuItem =
new NativeMenuItem( "menu 2 nested item 1" );
subMenuItem3.addEventListener( Event.SELECT, menuItemSelected );

childSubMenu.submenu.addItem( subMenuItem3 );
return subMenu;
}
// called on click
private function menuItemSelected( evt : Event ):void
{
var item:NativeMenuItem = evt.target as NativeMenuItem;
output.appendText( "CLICKED ON: "
+ item.label + File.lineEnding );
}
} // close class
} // close package

Testing the native menus

Now the application is ready to be tested. To test it, go back to the Flash ch06p01.fla. project . Then run the application by selecting the Test Movie command from the Flash CS4 Controls menu. Once it has been compiled and executed, right- click (or on Mac OS X systems, Ctrl- click) the button at the center of the stage. The native menu you’ve prepared will appear. You can see the application in Figure 6-4.

Essential_air_0604
Figure 6-4. The ch06p01.fla project in Flash

Each time you select an item from the context menu, the label of the selected element will be displayed in the TextArea. In the next section, you’ll learn how to use window- and application- level menus in real- world applications.

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

Latest Cloud Developer Stories
"ZeroStack is a startup in Silicon Valley. We're solving a very interesting problem around bringing public cloud convenience with private cloud control for enterprises and mid-size companies," explained Kamesh Pemmaraju, VP of Product Management at ZeroStack, in this SYS-CON.tv i...
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 Sen...
"Codigm is based on the cloud and we are here to explore marketing opportunities in America. Our mission is to make an ecosystem of the SW environment that anyone can understand, learn, teach, and develop the SW on the cloud," explained Sung Tae Ryu, CEO of Codigm, in this SYS-CO...
High-velocity engineering teams are applying not only continuous delivery processes, but also lessons in experimentation from established leaders like Amazon, Netflix, and Facebook. These companies have made experimentation a foundation for their release processes, allowing them ...
"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 SY...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021



SYS-CON Featured Whitepapers
ADS BY GOOGLE