ActionScript 2.0 Language Reference |
|
|
|
| ActionScript classes > ContextMenu > ContextMenu constructor | |||
public ContextMenu([callbackFunction:Function])
Creates a new ContextMenu object. You can optionally specify an identifier for an event handler when you create the object. The specified function is called when the user invokes the context menu, but before the menu is actually displayed. This is useful for customizing menu contents based on application state or based on the type of object (movie clip, text field, or button) or the Timeline that the user right-clicks or Control-clicks. (For an example of creating an event handler, see ContextMenu.onSelect.)
Availability: ActionScript 1.0; Flash Player 7
callbackFunction:Function [optional] - A reference to a function that is called when the user right-clicks or Control-clicks, before the menu is displayed.
The following example hides all the built-in objects in the Context menu. (However, the Settings and About items still appear, because they cannot be disabled.)
var newMenu:ContextMenu = new ContextMenu(); newMenu.hideBuiltInItems(); this.menu = newMenu;
In this example, the specified event handler, menuHandler, enables or disables a custom menu item (using the ContextMenu.customItems array) based on the value of a Boolean variable named showItem. If false, the custom menu item is disabled; otherwise, it's enabled.
var showItem = true; // Change this to false to remove
var my_cm:ContextMenu = new ContextMenu(menuHandler);
my_cm.customItems.push(new ContextMenuItem("Hello", itemHandler));
function menuHandler(obj, menuObj) {
if (showItem == false) {
menuObj.customItems[0].enabled = false;
} else {
menuObj.customItems[0].enabled = true;
}
}
function itemHandler(obj, item) {
//...put code here...
trace("selected!");
}
this.menu = my_cm;
When the user right-clicks or Control-clicks the Stage, the custom menu is displayed.
menu (Button.menu property), onSelect (ContextMenu.onSelect handler), customItems (ContextMenu.customItems property), hideBuiltInItems (ContextMenu.hideBuiltInItems method), menu (MovieClip.menu property), menu (TextField.menu property)
|
|
|
|