In the next example, a
menu items of the ContextMenu object,
var my_cm:ContextMenu = new ContextMenu();
for(eachProp in my_cm.builtInItems) {
var propName = eachProp;
var propValue = my_cm.builtInItems[propName];
trace(propName + ": " + propValue);
}
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
Availability: ActionScript 1.0; Flash Player 7
Parameters
callbackFunction:Function
user right-clicks or Control-clicks, before the menu is displayed.
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,
item (using the
ContextMenu.customItems
named
. If
showItem
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;
loop enumerates through all names and values of the built-in
for..in
my_cm
ContextMenu.onSelect
[optional] - A reference to a function that is called when the
, the custom menu item is disabled; otherwise, it's enabled.
false
.
.)
, enables or disables a custom menu
menuHandler
array) based on the value of a Boolean variable
ContextMenu
445
Need help?
Do you have a question about the FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE and is the answer not in the manual?