MACROMEDIA FLASH 8-COMPONENTS LANGUAGE Reference page 897

Components language reference
Table of Contents

Advertisement

4.
In the Actions panel, on the first frame, enter the following code to add an event listener
to listen for
click
menu and displays the name of the selected menu item in the Output panel:
/**
Requires:
- Menu component in library
- Button component in library
*/
import mx.controls.Button;
import mx.controls.Menu;
this.createClassObject(Button, "menu_button", 10, {label:"Launch
Menu"});
// Create a menu.
var my_menu:Menu = Menu.createMenu();
// Add some menu items.
my_menu.addMenuItem("Open");
my_menu.addMenuItem("Close");
my_menu.addMenuItem("Save");
my_menu.addMenuItem("Revert");
// Add a change-listener to Menu to detect which menu item is selected.
var menuListener:Object = new Object();
menuListener.change = function(evt_obj:Object) {
var item_obj:Object = evt_obj.menuItem;
trace("Item selected: "+item_obj.attributes.label);
};
my_menu.addEventListener("change", menuListener);
// Add a button listener that displays the menu when the button is
clicked.
var buttonListener:Object = new Object();
buttonListener.click = function(evt_obj:Object) {
var my_button:Button = evt_obj.target;
// Display the menu at the bottom of the button.
my_menu.show(my_button.x, my_button.y + my_button.height);
};
menu_button.addEventListener("click", buttonListener);
5.
Select Control > Test Movie.
Click the Launch Menu button to display the menu. When you select a menu item, a
statement reports the selection in the Output panel.
trace()
events on the button. The code also listens for a
Creating an application with the Menu component (Flash Professional only)
event on the
change
893

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?

This manual is also suitable for:

Flash 8

Table of Contents