MACROMEDIA FLASH MX 2004-USING COMPONENTS Use Manual page 545

Using components
Hide thumbs Also See for FLASH MX 2004-USING COMPONENTS:
Table of Contents

Advertisement

Creating an application with the Menu component (Flash Professional only)
In the following example, a developer is building an application and uses the Menu component to
expose some of the commands that users can issue, such as Open, Close, and Save.
To create an application with the Menu component:
Select File > New and create a Flash document.
1.
Drag the Menu component from the Components panel to the Stage and delete it.
2.
This adds the Menu component to the library without adding it to the application. Menus are
created dynamically through ActionScript.
Drag a Button component from the Components panel to the Stage.
3.
The button will be used to activate the menu.
In the Property inspector, give the button the instance name commandBtn, and change its text
4.
property to Commands.
In the Actions panel on the first frame, enter the following code to add an event listener to listen
5.
for
events on the
click
// Create a menu
var myMenu = mx.controls.Menu.createMenu();
// Add some menu items
myMenu.addMenuItem("Open");
myMenu.addMenuItem("Close");
myMenu.addMenuItem("Save");
myMenu.addMenuItem("Revert");
// Add a change-listener to Menu to detect which menu item is selected
var changeListener = new Object();
changeListener.change = function(event) {
var item = event.menuItem;
trace("Item selected: " + item.attributes.label);
}
myMenu.addEventListener("change", changeListener);
// Add a button that displays the menu when the button is clicked
var listener = new Object();
listener.click = function(evtObj) {
var button = evtObj.target;// get reference to the button
// Display the menu at the bottom of the button
_root.myMenu.show(button.x, button.y + button.height);
}
commandBtn.addEventListener("click", listener);
Select Control > Test Movie.
6.
Click the Commands button to see the menu appear. When you select a menu item, a
statement reports the selection in the Output panel.
trace()
instance:
commandBtn
Menu component (Flash Professional only)
545

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents