User Guide

518 Chapter 7: ActionScript for Flash
Property summary for the ContextMenu class
Event handler summary for the ContextMenu class
Constructor for the ContextMenu class
Availability
Flash Player 7.
Usage
new ContextMenu ([callBackFunction])
Parameters
callBackFunction
A reference to a function that is called when the user right-clicks or
Control-clicks, before the menu is displayed. This parameter is optional.
Returns
A reference to a ContextMenu object.
Description
Constructor; 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.)
Example
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, its enabled.
Property Description
ContextMenu.builtInItems
An object whose members correspond to built-in context
menu items.
ContextMenu.customItems
An array, undefined by default, that contains
ContextMenuItem objects.
Property Description
ContextMenu.onSelect
Invoked before the menu is displayed.