【AS3代码】在上下文菜单(右键菜单)中添加自定义项
package
{
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
public class Main extends Sprite
{
private var b:ContextMenuItem = new ContextMenuItem("XXX"); //添加新项
private var c:ContextMenuItem = new ContextMenuItem("王翔博客"); //添加新项
public function Main():void
{
c.separatorBefore = true; //在当前项上方添加一个分隔符
var arr:Array = [b,c];
var a:ContextMenu = new ContextMenu();
a.hideBuiltInItems(); //隐藏所有系统项
a.customItems = arr; //将新添加的项,添加到上下文菜单里
this.contextMenu = a; //将新的设置绑定到舞台
c.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, xuan); //监听点击上下文菜单选项后触发事件
}
private function xuan(evt:ContextMenuEvent):void
{
c.enabled = false;
c.caption = "你已经点过了";
navigateToURL(new URLRequest("http://www.baidu.com"));
}
}
}
{
import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
public class Main extends Sprite
{
private var b:ContextMenuItem = new ContextMenuItem("XXX"); //添加新项
private var c:ContextMenuItem = new ContextMenuItem("王翔博客"); //添加新项
public function Main():void
{
c.separatorBefore = true; //在当前项上方添加一个分隔符
var arr:Array = [b,c];
var a:ContextMenu = new ContextMenu();
a.hideBuiltInItems(); //隐藏所有系统项
a.customItems = arr; //将新添加的项,添加到上下文菜单里
this.contextMenu = a; //将新的设置绑定到舞台
c.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, xuan); //监听点击上下文菜单选项后触发事件
}
private function xuan(evt:ContextMenuEvent):void
{
c.enabled = false;
c.caption = "你已经点过了";
navigateToURL(new URLRequest("http://www.baidu.com"));
}
}
}