flash.ui
public final class ContextMenuItem
继承ContextMenuItem Inheritance EventDispatcher Inheritance Object

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

可以使用 ContextMenuItem 类来创建在 Flash Player 上下文菜单中显示的自定义菜单项。 每个 ContextMenuItem 对象都有一个显示在上下文菜单中的标题(文本)。 若要向上下文菜单中添加新项,请将其添加到 ContextMenu 对象的 customItems 数组。

利用 ContextMenuItem 类的属性,您可以启用或禁用特定菜单项,也可以显示或隐藏菜单项。

可以为 menuItemSelect 事件编写事件处理程序,以便在用户选择菜单项时为其添加功能。

自定义菜单项出现在上下文菜单的顶部,并位于所有内置菜单项之上。 自定义菜单项与内置菜单项始终由分隔条隔开。

限制:

注意:如果播放器运行在非英语系统上,标题字符串将同时与英语列表和对应的本地化字符串进行比较。

查看示例

另请参见

ContextMenu class
ContextMenuBuiltInItems class



公共 属性
 属性定义方
  caption : String
指定上下文菜单中显示的菜单项标题(文本)。
ContextMenuItem
 Inheritedconstructor : Object
对类对象或给定对象实例的构造函数的引用。
Object
  enabled : Boolean
指示指定的菜单项处于启用状态还是禁用状态。
ContextMenuItem
 Inheritedprototype : Object
[static] 对类或函数对象的原型对象的引用。
Object
  separatorBefore : Boolean
指示指定的菜单项上方是否显示分隔条。
ContextMenuItem
  visible : Boolean
指示在显示 Flash Player 上下文菜单时指定菜单项是否可见。
ContextMenuItem
公共 方法
 方法定义方
  
ContextMenuItem(caption:String, separatorBefore:Boolean = false, enabled:Boolean = true, visible:Boolean = true)
创建一个可添加到 ContextMenu.customItems 数组的新 ContextMenuItem 对象。
ContextMenuItem
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
使用 EventDispatcher 对象注册事件侦听器对象,以使侦听器能够接收事件通知。
EventDispatcher
  
创建并返回指定的 ContextMenuItem 对象的副本。
ContextMenuItem
 Inherited
将事件调度到事件流中。
EventDispatcher
 Inherited
检查 EventDispatcher 对象是否为特定事件类型注册了任何侦听器。
EventDispatcher
 Inherited
指示对象是否已经定义了指定的属性。
Object
 Inherited
指示 Object 类的实例是否在指定为参数的对象的原型链中。
Object
 Inherited
指示指定的属性是否存在、是否可枚举。
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
从 EventDispatcher 对象中删除侦听器。
EventDispatcher
 Inherited
设置循环操作动态属性的可用性。
Object
 Inherited
返回指定对象的字符串表示形式。
Object
 Inherited
返回指定对象的原始值。
Object
 Inherited
检查是否用此 EventDispatcher 对象或其任何始祖为指定事件类型注册了事件侦听器。
EventDispatcher
事件
 事件摘要定义方
 Inherited Flash Player 获得操作系统焦点并变为活动状态时调度。EventDispatcher
 Inherited Flash Player 失去操作系统焦点并变为非活动状态时调度。EventDispatcher
   用户从上下文菜单中选择项时调度。ContextMenuItem
属性详细信息
caption属性
caption:String  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

指定上下文菜单中显示的菜单项标题(文本)。 有关 caption 值限制,请参阅 ContextMenuItem 类概述。


实现
    public function get caption():String
    public function set caption(value:String):void
enabled属性 
enabled:Boolean  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

指示指定的菜单项处于启用状态还是禁用状态。

默认值为 true.


实现
    public function get enabled():Boolean
    public function set enabled(value:Boolean):void
separatorBefore属性 
separatorBefore:Boolean  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

指示指定的菜单项上方是否显示分隔条。

注意:任何自定义菜单项和内置菜单项之间始终会出现分隔条。

默认值为 false.


实现
    public function get separatorBefore():Boolean
    public function set separatorBefore(value:Boolean):void
visible属性 
visible:Boolean  [read-write]

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

指示在显示 Flash Player 上下文菜单时指定菜单项是否可见。

默认值为 true.


实现
    public function get visible():Boolean
    public function set visible(value:Boolean):void
构造函数详细信息
ContextMenuItem()构造函数
public function ContextMenuItem(caption:String, separatorBefore:Boolean = false, enabled:Boolean = true, visible:Boolean = true)

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

创建一个可添加到 ContextMenu.customItems 数组的新 ContextMenuItem 对象。

参数
caption:String — 指定与菜单项关联的文本。 有关 caption 值限制,请参阅 ContextMenuItem 类概述。
 
separatorBefore:Boolean (default = false) — 指定分隔条是否显示在上下文菜单中的菜单项上方。 默认值为 false
 
enabled:Boolean (default = true) — 指定菜单项在上下文菜单中是处于启用状态还是禁用状态。 默认值为 true(启用)。 此参数是可选的。
 
visible:Boolean (default = true) — 指定菜单项是否可见。 默认值为 true(可见)。
方法详细信息
clone()方法
public function clone():ContextMenuItem

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

创建并返回指定的 ContextMenuItem 对象的副本。 该副本包含初始对象的所有属性。

返回
ContextMenuItem — 包含原始对象的所有属性的 ContextMenuItem 对象。
事件详细信息
menuItemSelect 事件
事件对象类型: flash.events.ContextMenuEvent
ContextMenuEvent.type property = flash.events.ContextMenuEvent.MENU_ITEM_SELECT

语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9

用户从上下文菜单中选择某一项时调度。 用户通过单击其指针设备的辅助按钮来生成上下文菜单。

定义 menuItemSelect 事件对象的 type 属性值。

此事件具有以下属性:

属性
bubblesfalse
cancelablefalse;没有要取消的默认行为。
contextMenuOwner菜单附加到的显示列表对象。
currentTarget当前正在使用某个事件侦听器处理 Event 对象的对象。
mouseTarget用户右键单击以显示上下文菜单的显示列表对象。
target已选定的 ContextMenuItem 对象。 target 不一定是显示列表中注册此事件侦听器的对象。 请使用 currentTarget 属性来访问显示列表中当前正在处理此事件的对象。
示例 如何使用示例

下例使用 ContextMenuBuiltInItemsExample 类从舞台中删除默认的上下文菜单项,并添加新的菜单项。 这是由以下步骤完成的:
  1. 声明属性 myContextMenu,然后将其赋给新的 ContextMenu 对象。
  2. 调用 removeDefaultItems() 方法,该方法将删除所有内置的上下文菜单项(“打印”除外)。
  3. 调用 addCustomMenuItems() 方法,该方法使用数组的 push() 方法将称为 Hello World 的菜单项放入 customItems 数组。
  4. Hello World 上下文菜单项添加到舞台的上下文菜单项列表中。
  5. 将具有文本“在此处右键单击”的 TextField 对象添加到舞台。
package {
    import flash.ui.ContextMenu;
    import flash.ui.ContextMenuItem;
    import flash.ui.ContextMenuBuiltInItems;
    import flash.display.Sprite;
    import flash.text.TextField;

    public class ContextMenuItemExample extends Sprite {
        private var myContextMenu:ContextMenu;

        public function ContextMenuItemExample() {
            myContextMenu = new ContextMenu();
            removeDefaultItems();
            addCustomMenuItems();
            this.contextMenu = myContextMenu;
            addChild(createLabel());
        }

        private function removeDefaultItems():void {
            myContextMenu.hideBuiltInItems();

            var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
            defaultItems.print = true;
        }

        private function addCustomMenuItems():void {
            var item:ContextMenuItem = new ContextMenuItem("Hello World");
            myContextMenu.customItems.push(item);
        }
        
        private function createLabel():TextField {
            var txtField:TextField = new TextField();
            txtField.text = "Right Click Here";
            return txtField;
        }
    }
}




 

评论添加到页面后给我发送电子邮件 | 评论报告

当前页: http://livedocs.adobe.com/flash/9.0_cn/ActionScriptLangRefV3/flash/ui/ContextMenuItem.html