
ContextMenu
445
In the next example, a
for..in
loop enumerates through all names and values of the built-in
menu items of the ContextMenu object,
my_cm
.
var my_cm:ContextMenu = new ContextMenu();
for(eachProp in my_cm.builtInItems) {
var propName = eachProp;
var propValue = my_cm.builtInItems[propName];
trace(pr ": " + 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
ContextMenu.onSelect
.)
Availability:
ActionScript 1.0; Flash Player 7
Parameters
callbackFunction
:Function
[optional] - A reference to a function that is called when the
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,
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;
Содержание FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Страница 1: ...ActionScript 2 0 Language Reference ...
Страница 1352: ...1352 ActionScript classes ...