|
Comments
Did you read today's front page stories & breaking news?
SYS-CON.TV
|
From Author Blogs
Creating AIR submenus for a native menu with Flash CS4 - Part 2 (The Essential Guide to Flash CS4 AIR Development Highlight)
Dec. 19, 2008 07:13 AM
In the first part of this article dedicated on AIR menus you've learned how to create an AIR native menu (read the full Creating AIR native menu with Flash CS4 - Part 1 article) To create a submenu item, you use the NativeMenuItem class . Begin by opening the Ch06p01.as class and add the createFirstSubMenu() method , which creates an item of the NativeMenuItem class and adds two elements. This item will be used as a first submenu of the native menu you’re creating. Here’s the code: private function createFirstSubMenu():NativeMenuItem Next, create an instance of the NativeMenuItem class by showing the label that it needs to be associated with. Assign an instance of the NativeMenu class to the submenu property of the element you’ve just created. The native menu object associated with the submenu property will contain the subitems you’ll create for this element of the menu. // create first submenu Follow these steps to define the elements that will be displayed as children of the element of the menu you’ve just created: 1. Instantiate an object of the NativeMenuItem class by giving the constructor a label for the element. 2. Register an event listener method for the SELECT event (Event.SELECT). Each time the user selects this element from the menu, the menuItemSelected() method will 3. Finally, add the element of the menu you’ve created to the submenu property of the submenu you’re creating with the addItem() method of the NativeMenuItem // create first submenu child Create a second object of the NativeMenuItem class. Then register the selection event of the element to the menuItemSelected() method . Finally, add the element to the submenu you’re creating. Here’s the code:
// create a second child, register event listener for Next, return the menu you’ve created so that it can be added as a child of the main context menu.
return subMenu; The first submenu has been created and is ready to use. Before testing your application, you have to define the createSecondSubMenu() method , which will deal with initializing the second submenu of the context menu you’re creating. The following sequence of operations to execute is very similar to the procedure to create the first submenu: 1. Create an object of the NativeMenuItem class. 2. Assign an instance of the NativeMenu class to its submenu property. 3. Populate the submenu object with the elements you like. This menu will also have a submenu and will contain an element separator. For each item on the menu, you will have to register a selection event on the menuItemSelected() event listener method . Here’s the code:
private function createSecondSubMenu():NativeMenuItem Creating element separators
The element separators in a native menu are in turn instances of the
NativeMenuItem class. The separators display a horizontal line instead
of a text label. The line shows the border between different groups of
elements. To create an element separator, you instantiate an object of
the NativeMenuItem class, providing it with a Boolean value (true) as a
second argument. This second argument is false by default, and tells
the object that it has to ignore the text label property and show a
separator line.
// add a separator item After the element separator, you create and add a new item to the submenu. Then you create and add an element that will contain another submenu. To populate the internal submenu, populate the submenu property of a native element of the menu with the necessary items. Here’s the code:
// create a second child, register event listener for
// create a new item as an internal submenu
// initialize child container
// create a child, register event listener for
var subMenuItem3:NativeMenuItem = new NativeMenuItem( "menu 2 nested item 1" ); 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.
Latest Cloud Developer Stories
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week
Breaking Cloud Computing News
|
|||||||||||||||||||||||||||||||||||||||||||||||||