Flash Player 7.
The ContextMenu class provides runtime control over the items in the Flash Player context menu, which appears when a user right-clicks (Windows) or Control-clicks (Macintosh) on Flash Player. You can use the methods and properties of the ContextMenu class to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print), or create copies of menus.
You can attach a ContextMenu object to a specific button, movie clip, or text field object, or to an entire movie level. You use the menu property of the Button, MovieClip, or TextField classes to do this. For more information about the menu property, see Button.menu, MovieClip.menu, and TextField.menu.
To add new items to a ContextMenu object, you create a ContextMenuItem object, and then add that object to the ContextMenu.customItems array. For more information about creating context menu items, see the ContextMenuItem class entry.
Flash Player has three types of context menus: the standard menu (which appears when you right-click in Flash Player), the edit menu (which appears when you right-click over a selectable or editable text field), and an error menu (which appears when a SWF file has failed to load into Flash Player.) Only the standard and edit menus can be modified with the ContextMenu class.
Custom menu items always appear at the top of the Flash Player context menu, above any visible built-in menu items; a separator bar distinguishes built-in and custom menu items. You can add no more than 15 custom items to a context menu. You cannot remove the Settings menu item from the context menu. The Settings menu item is required in Flash so users can access the settings that affect privacy and storage on their computers. You also cannot remove the About menu item from the context menu, which is required so users can find out what version of Flash Player they are using.
You must use the constructor new ContextMenu() to create a ContextMenu object before calling its methods.
| Method | Description |
|---|---|
ContextMenu.copy() |
Returns a copy of the specified ContextMenu object. |
ContextMenu.hideBuiltInItems() |
Hides most built-in items in the Flash Player context menu. |
| Property | Description |
|---|---|
|
An object whose members correspond to built-in context menu items. |
ContextMenu.customItems |
An array, undefined by default, that contains ContextMenuItem objects. |
| Property | Description |
|---|---|
|
Invoked before the menu is displayed. |
Flash Player 7.
new ContextMenu ([callBackFunction])
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.
A reference to a ContextMenu object.
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.)
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.
Button.menu, ContextMenu.onSelect, ContextMenu.customItems, ContextMenu.hideBuiltInItems(), MovieClip.menu, TextField.menu
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/mx2004/main_7_2/00001276.html
Comments
recoveredfromflashMX2004 said on Aug 4, 2004 at 2:30 PM : recoveredfromflashMX2004 said on Aug 4, 2004 at 2:32 PM : ctvrtlik said on Oct 1, 2004 at 11:22 AM : M.Q said on Nov 16, 2004 at 11:37 PM : tectonik said on Aug 26, 2005 at 4:15 AM : pixeldrew said on Jan 22, 2006 at 3:19 AM :