# ContextMenu object

#### Availability

Flash Player 7.

#### Description

The ContextMenu object 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 the Flash Player. You can use the methods and properties of the ContextMenu object to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print), or create copies.

To make a ContextMenu object active, you attach it to an object or Timeline by using the `menu` property of the MovieClip, TextField, and Button objects. In the simplest case, you can assign a ContextMenu object to `_root.menu`, which... You can assign the same ContextMenu object to as many movie clips, buttons, and text fields as you please. (For more information about the `menu` property, see `Button.menu`, `MovieClip.menu`, and `TextField.menu`.)

To add new items to a ContextMenu object, first the ContextMenuItem object and then add that menu item to the `ContextMenu.customItems` array, which contains references to the custom menu items available to a particular ContextMenu object.

To create new menu items, use the ContextMenuItem object. Each item you create has an associated callback handler that's called by Flash Player when that menu item is chosen. For more information about creating context menu items, see the ContextMenuItem object entry.

## Meth

Method | Description
--- | ---
`ContextMenu.copy()` | Returns a copy of the specified ContextMenu object.
`ContextMenu.hideBuiltInItems()` | Hides all built-in items in the Flash Player context menu.

od summary for the ContextMenu object

## Property summary for the ContextMenu object

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.

## Event handler summary for the ContextMenu object

Property | Description
--- | ---
`ContextMenu.callback` | A callback handler that is called when the specified context menu object is invoked.

## Constructor for the ContextMenu object

#### 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

An instance of the ContextMenu object.

#### Description

Constructor; creates a new ContextMenu object. You can optionally specify an identifier for a callback handler (a function) 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) that the user right-clicks or Control-clicks. (For more information about the callback function, see `ContextMenu.callback`.)

#### Example

The following example hides all the built-in objects on the Context menu. (Note: the Settings... item still appears, as it cannot be disabled.)

    var newMenu = new ContextMenu();
    newMenu.hideBuiltInItems();
    _root.menu = newMenu;

In this example, the specified callback function, `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 = false; // Change this to true to see its effect
    menu_cm = new ContextMenu(menuHandler);
    menu_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) {
    }
    _root.menu = menu_cm;

#### See also

`Button.menu`, `ContextMenu.callback`, `ContextMenu.customItems`, `ContextMenu.hideBuiltInItems()`, `MovieClip.menu`, `TextField.menu`