User Guide
MenuBar.labelFunction 963
MenuBar.labelFunction
Availability
Flash Player 6 (6.0.79.0).
Edition
Flash MX Professional 2004.
Usage
menuBarInstance.labelFunction
Description
Property; a function that determines what to display in each menu’s label text. The function
accepts the XML node associated with an item as a parameter and returns a string to be used
as label text. This property is passed to any menus created from the menu bar. The default
value is
undefined.
After the
dataProvider property is set, this property is read-only.
Example
The following example uses a label function to build and return a custom label, such as New
(Control +N), from the node attributes.
Drag an instance of the MenuBar component onto the Stage, and enter the instance name
my_mb in the Property inspector. Add the following code to Frame 1 of the timeline:
/**
Requires:
- MenuBar component on Stage (instance name: my_mb)
*/
var my_mb:mx.controls.MenuBar;
var my_menu:mx.controls.Menu = my_mb.addMenu("File");
my_menu.addMenuItem({label:"New", data:"Control+N",
instanceName:"newInstance"});
my_menu.addMenuItem({label:"Open", data:"Control+O",
instanceName:"openInstance"});
my_menu.addMenuItem({label:"Close", data:"Control+W",
instanceName:"closeInstance"});
//Format XML data provided for menu.
my_menu.labelFunction = function(node:XMLNode):String {
var attrb:Object = node.attributes;
return (attrb.label + " (" + attrb.data + ")");
};