引用http://blog.csdn.net/liyong1115/archive/2008/05/15/2447393.aspx
例子1、
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
// 为鼠标右键添加关闭当前浏览器窗口的菜单
var contextMenu : ContextMenu = new ContextMenu();
contextMenu.hideBuiltInItems(); // 隐藏一些内建的鼠标右键菜单项
var contextMenuItem : ContextMenuItem = new ContextMenuItem("关闭本窗口");
contextMenu.customItems.push(contextMenuItem);
contextMenuItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function(event : ContextMenuEvent) : void{
navigateToURL(new URLRequest("javascript:window.close()"), "_self");
});
this.contextMenu = contextMenu; // 这里的this为Application对象 this可以换成其他组件
例子2
package fb.copyright{
import flash.ui.*
import flash.display.*
import flash.net.*
import flash.events.ContextMenuEvent
public class Copyright{
private var myName:String="作者:zjs35"
private var myUrl:String="http://zjs35.5dblog.com"
private var target:InteractiveObject
public function Copyright(target:InteractiveObject){
this.target=target
this.removeAndAddItem()
}
private function removeAndAddItem():void{
var myContextMenu = new ContextMenu();
var item:ContextMenuItem=new ContextMenuItem(myName)
myContextMenu.hideBuiltInItems();
myContextMenu.customItems.push(item)
target.contextMenu=myContextMenu
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemSelectHandler);
}
private function itemSelectHandler(e:ContextMenuEvent):void{
navigateToURL(new URLRequest(myUrl),"_blank")
}
}
}
使用方法:
代码:
import fb.copyright.*
var cr:Copyright=new Copyright(this)