Welcome, guest Sign In

ASTRA Menu

Menu is a UI component that displays a hierarchical menu structure that can be used to provide convenient access to various application functionality, sorted by categories.

Getting Started: Menu for Flash CS3

Similar to other Flash components, you can create a Menu by placing an instance on the stage or by using ActionScript to create an instance dynamically.

Initializing a Menu on the Stage

One way to create a Menu is to drag it from the Components panel to the stage and give it a name in the Properties panel (we'll use the name "menu" in this example). This will immediately create a Menu instance and add it to the display list. To populate it and show the menu, you'll need to use ActionScript. So we'll show how to do that.

Screen capture of Menu

To see a live example, please install Adobe Flash Player version 9 or higher.

Download the FLA file.

//import the required data class
import com.yahoo.astra.fl.controls.Menu;
import com.yahoo.astra.fl.data.XMLDataProvider;

//Create some XML to populate the menu
	var colors:XML = 
	<root>
		<menuitem label="Red" />
		<menuitem label="Orange" />
		<menuitem label="Yellow" />
		<menuitem label="Green" />
		<menuitem label="Blue" />
		<menuitem label="Purple" />
	</root>

	//give the menu the xml data above
	menu.dataProvider = new XMLDataProvider(colors);

	//cause the button to display the menu
	button.addEventListener("click", showMenu);

	//display the menu 
	function showMenu(event:MouseEvent):void
	{
		//display the menu at the bottom of the button
		menu.show();
	}

Initializing a Menu with ActionScript

To include a Menu within your application with ActionScript, you must first add the Menu component to your library. You can do so by dragging it from the Components panel directly to the library, or by dragging an instance to the stage, and immediately removing it (it will stay in your library). Additionally, you need to import the following classes for use in your class or frame script.

import com.yahoo.astra.fl.controls.Menu;

The class com.yahoo.astra.fl.controls.Menu is the main required class for a Menu control.

To create the menu, you call the Menu.createMenu() method. This is a static method, so you actually call it on the Menu class (hence the uppercase "Menu"). This method takes a couple of parameters; the first is the object you want your menu to be attached to, and the second is some XML data. Note that the first parameter will affect its placement in terms of layering for the display list (i.e. what goes on top of what), as well as its x,y placement.

	//import the Menu
	import com.yahoo.astra.fl.controls.Menu;

	//Create some XML to populate the menu
	var colors:XML = 
	<root>
		<menuitem label="Red" />
		<menuitem label="Orange" />
		<menuitem label="Yellow" />
		<menuitem label="Green" />
		<menuitem label="Blue" />
		<menuitem label="Purple" />
	</root>

	//create a menu "out of the blue" and give it the xml data above
	var menu:Menu = Menu.createMenu(this, colors);

	//display the menu at 10 pixels from the top and 15 pixels 
	//from the left of the stage
	menu.show(15, 10);

For additional topics, please read Using Menu, or take a look at the Examples section for functional demonstrations. The ActionScript 3.0 Class Reference contains full details on every property, method, and style available to the Menu component.

YDN LIBRARIES & BEST PRACTICES

YAHOO! APIs & WEB SERVICES

LANGUAGE CENTERS

Copyright © 2008 Yahoo! Inc. All rights reserved. Copyright | Privacy Policy

Help us continue to improve the Yahoo! Developer Network - Send Your Suggestions