MACROMEDIA FLASH 8-COMPONENTS LANGUAGE Reference page 922

Components language reference
Table of Contents

Advertisement

Example
The following example creates a button and a two-item menu. When the user clicks the
button, a listener for a button click event displays the menu. When the user clicks a second
time, the menu is hidden and a listener for the
"Menu closed" in the Output panel.
You first drag a Menu component and a Button component to the library and then add the
following code to Frame 1:
/**
Requires:
- Menu component in library
- Button component in library
*/
import mx.controls.Button;
import mx.controls.Menu;
this.createClassObject(Button, "my_button", 10);
// Create an XML object to act as a factory.
var my_xml:XML = new XML();
// The item created next does not appear in the menu.
// The createMenu() method call (below) expects to
// receive a root element whose children will become
// the items. This is just a simple way to create that
// root element and give it a convenient name.
var menuDP_obj:Object = my_xml.addMenuItem("XXXXX");
// Add the menu items.
menuDP_obj.addMenuItem({label:"1st Item"});
menuDP_obj.addMenuItem({label:"2nd Item"});
// Create the Menu object.
var my_menu:Menu = Menu.createMenu(this, menuDP_obj);
// Add a button that displays the menu when the button is clicked.
var buttonListener:Object = new Object();
buttonListener.click = function(evt_obj:Object) {
// get reference to the button
var the_button:Button = evt_obj.target;
// Display the menu at the bottom of the button.
my_menu.show(the_button.x, the_button.y + the_button.height);
};
my_button.addEventListener("click", buttonListener);
// Create listener object.
var menuListener:Object = new Object();
918
Menu component (Flash Professional only)
event,
menuHide
menuListener
, displays

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash 8

Table of Contents