Packageflash.events
Classpublic class ContextMenuEvent
InheritanceContextMenuEvent Inheritance Event Inheritance Object

Flash Player dispatches ContextMenuEvent objects when a user generates or interacts with the context menu. Users generate the context menu by clicking the secondary button of the user's pointing device (usually a mouse or a trackball). There are two types of ContextMenuEvent objects:

View the examples.

See also
ContextMenu class, ContextMenuItem class, ContextMenuEvent.MENU_ITEM_SELECT, ContextMenuEvent.MENU_SELECT


Public Constants
Hide Inherited Public Constants
Show Inherited Public Constants
 PropertyDefined by
 InheritedACTIVATE : String = "activate"
[static] Dispatched when Flash Player gains operating system focus and becomes active.
Event
 InheritedADDED : String = "added"
[static] Dispatched when a display object is added to the display list.
Event
 InheritedCANCEL : String = "cancel"
[static] Dispatched when a file upload or download is cancelled by the user.
Event
 InheritedCHANGE : String = "change"
[static] Dispatched after a control's value is modified.
Event
 InheritedCLOSE : String = "close"
[static] Dispatched by an Socket or XMLSocket object after a network connection is closed.
Event
 InheritedCOMPLETE : String = "complete"
[static] Dispatched when data has loaded successfully.
Event
 InheritedCONNECT : String = "connect"
[static] Dispatched when a network connection has been established.
Event
 InheritedDEACTIVATE : String = "deactivate"
[static] Dispatched when Flash Player loses operating system focus and is becoming inactive.
Event
 InheritedENTER_FRAME : String = "enterFrame"
[static] Dispatched when the playhead is entering a new frame.
Event
 InheritedID3 : String = "id3"
[static] Dispatched by a Sound object when ID3 data is available for an MP3 sound.
Event
 InheritedINIT : String = "init"
[static] Dispatched by a LoaderInfo object when the properties and methods of a loaded SWF file are accessible.
Event
  MENU_ITEM_SELECT : String = "menuItemSelect"
[static] Flash Player dispatches the menuItemSelect event when a user selects an item from a context menu.
ContextMenuEvent
  MENU_SELECT : String = "menuSelect"
[static] Flash Player dispatches the menuSelect event when a user first generates a context menu but before the contents of the context menu are displayed.
ContextMenuEvent
 InheritedMOUSE_LEAVE : String = "mouseLeave"
[static] Dispatched by the Stage object when the mouse pointer moves out of the Flash Player window area.
Event
 InheritedOPEN : String = "open"
[static] Dispatched by a LoaderInfo, URLLoader, URLStream or FileReference object when a network operation starts.
Event
 InheritedREMOVED : String = "removed"
[static] Dispatched when a display object is about to be removed from the display list.
Event
 InheritedRENDER : String = "render"
[static] Dispatched when the display list is about to be updated and rendered.
Event
 InheritedRESIZE : String = "resize"
[static] Dispatched when scaleMode property of the Stage object is set to StageScaleMode.NO_SCALE and the SWF file has been resized.
Event
 InheritedSCROLL : String = "scroll"
[static] Dispatched by a TextField object after the user scrolls.
Event
 InheritedSELECT : String = "select"
[static] Dispatched by a FileReference object when an item has been selected.
Event
 InheritedSOUND_COMPLETE : String = "soundComplete"
[static] Dispatched by a Sound object when a sound has finished playing.
Event
 InheritedTAB_CHILDREN_CHANGE : String = "tabChildrenChange"
[static] Dispatched by an InteractiveObject instance when the value of the object's tabChildren flag changes.
Event
 InheritedTAB_ENABLED_CHANGE : String = "tabEnabledChange"
[static] Dispatched by an InteractiveObject instance when the the object's tabEnabled flag changes.
Event
 InheritedTAB_INDEX_CHANGE : String = "tabIndexChange"
[static] Dispatched by an InteractiveObject instance when the value of the object's tabIndex property changes.
Event
 InheritedUNLOAD : String = "unload"
[static] Dispatched by a LoaderInfo object whenever a loaded object is removed using the unload() method of the Loader object, or when a second load is performed by the same Loader object and the orignal content is removed prior to the load beginning.
Event
Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties
 PropertyDefined by
 Inheritedbubbles : Boolean
Indicates whether an event is a bubbling event.
Event
 Inheritedcancelable : Boolean
Indicates whether the behavior associated with the event can be prevented.
Event
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  contextMenuOwner : InteractiveObject
The display list object to which the menu is attached.
ContextMenuEvent
 InheritedcurrentTarget : Object
Indicates the object that is actively processing the Event object with an event listener.
Event
 InheritedeventPhase : uint
Indicates the current phase in the event flow.
Event
  mouseTarget : InteractiveObject
The display list object on which the user context-clicked to display the context menu.
ContextMenuEvent
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
 Inheritedtarget : Object
Indicates the event target.
Event
 Inheritedtype : String
Indicates the type of event.
Event
Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods
 FunctionDefined by
  
ContextMenuEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, mouseTarget:InteractiveObject = null, contextMenuOwner:InteractiveObject = null)
Creates an Event object that contains specific information about menu events.
ContextMenuEvent
  
Creates a copy of the ContextMenuEvent object and sets the value of each property to match that of the original.
ContextMenuEvent
 Inherited
formatToString(className:String, ... arguments):String
A utility function that you use to implement the toString() method in your custom Event class.
Event
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
This method checks whether preventDefault() has been called on the event and returns true if preventDefault() has been called and false otherwise.
Event
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Cancels an event's default behavior if that behavior can be cancelled.
Event
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Prevents processing of any event listeners in the current node and any subsequent nodes in the event flow.
Event
 Inherited
Prevents processing of any event listeners in nodes subsequent to the current node in the event flow.
Event
  
Returns a string that contains all the properties of the ContextMenuEvent object.
ContextMenuEvent
 Inherited
Returns the primitive value of the specified object.
Object
Constant detail
MENU_ITEM_SELECT constant
public static const MENU_ITEM_SELECT:String = "menuItemSelect"

Flash Player dispatches the menuItemSelect event when a user selects an item from a context menu. The user generates the context menu by clicking the secondary button of the user's pointing device.

This event has the following characteristics:

PropertiesValues
targetThe ContextMenuItem object that has been selected. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.ui.ContextMenuItem
MENU_SELECT constant
public static const MENU_SELECT:String = "menuSelect"

Flash Player dispatches the menuSelect event when a user first generates a context menu but before the contents of the context menu are displayed. The user can then modify the set of context menu items based on the mouseTarget before displaying the menu. The user generates the context menu by clicking the secondary button of the user's pointing device.

This event has the following characteristics:

PropertiesValues
targetThe ContextMenu object that is about to be displayed. The target is not always the object in the display list that registered the event listener. Use the currentTarget property to access the object in the display list that is currently processing the event.
bubblesNo.
currentTargetIndicates the object that is actively processing the Event object with an event listener.
cancelableNo. There is no default behavior to cancel.

See also
flash.ui.ContextMenu
Property detail
contextMenuOwner property
contextMenuOwner:InteractiveObject  [read-write]

The display list object to which the menu is attached. This could be the mouse target (mouseTarget) or one of its ancestors in the display list.

Implementation
    public function get contextMenuOwner():InteractiveObject
    public function set contextMenuOwner(value:InteractiveObject):void
mouseTarget property
mouseTarget:InteractiveObject  [read-write]

The display list object on which the user context-clicked to display the context menu. This could be the display list object to which the menu is attached (contextMenuOwner) or one of its display list descendants.

Implementation
    public function get mouseTarget():InteractiveObject
    public function set mouseTarget(value:InteractiveObject):void
Constructor detail
ContextMenuEvent constructor

public function ContextMenuEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false, mouseTarget:InteractiveObject = null, contextMenuOwner:InteractiveObject = null)

Creates an Event object that contains specific information about menu events. Event objects are passed as parameters to event listeners.

Parameters
type:String — The type of the event. Possible values are:
  • ContextMenuEvent.MENU_ITEM_SELECT
  • ContextMenuEvent.MENU_SELECT
bubbles:Boolean (default = false) — Determines whether the Event object participates in the bubbling stage of the event flow. Event listeners can access this information through the inherited bubbles property.
cancelable:Boolean (default = false) — Determines whether the Event object can be cancelled. Event listeners can access this information through the inherited cancelable property.
mouseTarget:InteractiveObject (default = null) — The display list object on which the user context-clicked to display the context menu. This could be the contextMenuOwner or one of its display list descendants.
contextMenuOwner:InteractiveObject (default = null) — The display list object to which the menu is attached. This could be the mouseTarget or one of its ancestors in the display list.

See also
ContextMenuEvent.MENU_ITEM_SELECT, ContextMenuEvent.MENU_SELECT
Method detail
clone method

public override function clone():Event

Creates a copy of the ContextMenuEvent object and sets the value of each property to match that of the original.

Returns
Event — A new ContextMenuEvent object with property values that match those of the original.
toString method

public override function toString():String

Returns a string that contains all the properties of the ContextMenuEvent object. The string is in the following format:

[ContextMenuEvent type=value bubbles=value cancelable=value ... contextMenuOwner=value]

Returns
String — A string that contains all the properties of the ContextMenuEvent object.
Class examples

The following example uses the ContextMenuEventExample class to remove the normal right-click menu items from the stage and add a new menu item, which, if clicked, changes the color of a square on the stage. This is accomplished using the following steps:
  1. A property myContextMenu is declared and then assigned to a new ContextMenu object and a property redRectangle of type Sprite is declared.
  2. The method removeDefaultItems() is called, which removes all built-in right-click menu items except print.
  3. The method addCustomMenuItems() is called, which places an item called Reverse Colors menu selection into the defaultItems Array using the push() method of Array. A menuItemSelect event listener is added to the ContextMenuItem object and the associated method is called menuItemSelectHandler(). This method prints out some statements using trace() whenever the right-click menu is accessed and Reverse Colors is selected. Also the red square is turned black while the black text is turned red.
  4. Back in the constructor, an event listener of type menuSelect is added, along with the associated method menuSelectHandler, which simply prints out three statements using trace() every time an item in the right-click menu is opened (by right-clicking).
  5. The constructor then calls addChildren(), which draws a red square and adds it to the display list, which promptly displays it.
  6. Finally, myContextMenu is assigned to the redRectangle property's context menu so that the custom context menu is displayed only when the mouse is over the square.
package {
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.events.ContextMenuEvent;
    import flash.events.ContextMenuEvent;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.text.TextField;

    public class ContextMenuEventExample extends Sprite {
        private var myContextMenu:ContextMenu;
        private var menuLabel:String = "Reverse Colors";
        private var textLabel:String = "Right Click";
        private var redRectangle:Sprite;
        private var label:TextField;
        private var size:uint = 100;
        private var black:uint = 0x000000;
        private var red:uint = 0xFF0000;

        public function ContextMenuEventExample() {
            myContextMenu = new ContextMenu();
            removeDefaultItems();
            addCustomMenuItems();
            myContextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, menuSelectHandler);

            addChildren();
            redRectangle.contextMenu = myContextMenu;
        }

        private function addChildren():void {
            redRectangle = new Sprite();
            redRectangle.graphics.beginFill(red);
            redRectangle.graphics.drawRect(0, 0, size, size);
            addChild(redRectangle);
            redRectangle.x = size;
            redRectangle.y = size;
            label = createLabel();
            redRectangle.addChild(label);
        }

        private function removeDefaultItems():void {
            myContextMenu.hideBuiltInItems();
            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomMenuItems():void {
            var item:ContextMenuItem = new ContextMenuItem(menuLabel);
            myContextMenu.customItems.push(item);
            item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
        }

        private function menuSelectHandler(event:ContextMenuEvent):void {
            trace("menuSelectHandler: " + event);
        }

        private function menuItemSelectHandler(event:ContextMenuEvent):void {
            trace("menuItemSelectHandler: " + event);
            var textColor:uint = (label.textColor == black) ? red : black;
            var bgColor:uint = (label.textColor == black) ? black : red;
            redRectangle.graphics.clear();
            redRectangle.graphics.beginFill(bgColor);
            redRectangle.graphics.drawRect(0, 0, size, size);
            label.textColor = textColor;
        }

        private function createLabel():TextField {
            var txtField:TextField = new TextField();
            txtField.text = textLabel;
            return txtField;
        }
    }
}




 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/labs/flashauthoringpreview/flash/events/ContextMenuEvent.html