User Guide
948 MenuBar component (Flash Professional only)
6. In the Actions panel on Frame 1, enter the following code:
//Create listener object.
var mbListener:Object = new Object();
mbListener.change = function(evt_obj:Object) {
var menuItem_obj:Object = evt_obj.menuItem;
switch (menuItem_obj.attributes.instanceName) {
case "newInstance":
trace("New menu item");
break;
case "openInstance":
trace("Open menu item");
break;
case "closeInstance":
trace("Close menu item");
break;
}
trace(menuItem_obj);
};
//Add listener.
my_menu.addEventListener("change", mbListener);
This code creates a listener object, mblistener, that catches a menu item selection and
displays its name and the value of the menu item object.
7. Select Control > Test Movie to test the MenuBar component.
Customizing the MenuBar component
(Flash Professional only)
This component sizes itself according to the activator labels that are supplied through the
dataProvider property or the methods of the MenuBar class. When an activator button is in
a menu bar, it remains at a fixed size that is dependent on the font styles and the text length.
NOTE
You must call the addEventListener() method to register the listener with the menu
instance, not with the menu bar instance.