ContextMenuItem class

Availability

Flash Player 7.

Description

You use the ContextMenuItem class to create custom menu items to display in the Flash Player context menu. Each ContextMenuItem object has a caption (text) that's displayed in the context menu and a callback handler (a function) that's invoked when the menu item is selected. To add a new context menu item to a context menu, you add it to the customItems array of a ContextMenu object.

You can enable or disable specific menu items, make items visible or invisible, or change the caption or callback handler associated with a menu item.

Custom menu items appear at the top of the context menu, above any built-in items. A separator bar always divides custom menu items from built-in items. You can add no more than 15 custom items to the Flash Player context menu. Each item must contain at least one visible character— control characters, newlines, and other white space characters are ignored. No item can be more than 100 characters long. Items that are identical to any built-in menu item, or to another custom item, are ignored, whether the matching item is visible or not. Menu items are compared without regard to case, punctuation, or white space.

None of the following words can appear in a custom item: Macromedia, Flash Player, or Settings.

Method summary for the ContextMenuItem class

Method

Description

ContextMenuItem.copy()

Returns a copy of the specified ContextMenuItem object.

Property summary for the ContextMenuItem class

Property

Description

ContextMenuItem.caption

Specifies the text displayed in the menu item.

ContextMenuItem.enabled

Specifies whether the menu item is enabled or disabled.

ContextMenuItem.separatorBefore

Specifies whether a separator bar should appear above the menu item.

ContextMenuItem.visible

Specifies whether the menu item is visible or not.

Event handler summary for the ContextMenuItem class

Event handler

Description

ContextMenuItem.onSelect

Invoked when the menu item is selected.

Constructor for the ContextMenuItem class

Availability

Flash Player 7.

Usage

new ContextMenuItem(caption, callbackFunction, [ separatorBefore, [ enabled, [ visible ] ] ] )

Parameters

caption A string that specifies the text associated with the menu item.

callbackFunction A function that you define, which is called when the menu item is selected.

separatorBefore A Boolean value that indicates whether a separator bar should appear above the menu item in the context menu. This parameter is optional; its default value is false.

enabled A Boolean value that indicates whether the menu item is enabled or disabled in the context menu. This parameter is optional; its default value is true.

visible A Boolean value that indicates whether the menu item is visible or invisible. This parameter is optional; its default value is true.

Returns

Nothing.

Description

Constructor; creates a new ContextMenuItem object that can be added to the ContextMenu.customItems array.

Example

This example adds Start and Stop menu items, separated by a bar, to the ContextMenu object my_cm. The startHandler() function is called when Start is selected from the context menu; stopHandler() is called when Stop is selected. The ContextMenu object is applied to the root Timeline.

my_cm = new ContextMenu();
my_cm.customItems.push(new ContextMenuItem("Start", startHandler));
my_cm.customItems.push(new ContextMenuItem("Stop", stopHandler, true));
function stopHandler(obj, item) {
  trace("Stopping...");
}
function startHandler(obj, item) {
  trace("Starting...");
}
_root.menu = my_cm;