在Flash中管理鼠标右键

//最大限度的把鼠标的右键菜单去掉 :stage.showDefaultContextMenu = false;

package {
	import flash.display.Sprite;
	import flash.events.ContextMenuEvent;
	import flash.net.URLRequest;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuBuiltInItems;
	import flash.ui.ContextMenuItem;
	import flash.net.navigateToURL;

	/* 
     *author : SinSoul  
     *blogs: http://www.cnblogs.com/sinsoul  
     */ 

	public class Main extends Sprite {
		private var onMenu:ContextMenu;
		private var onBuiltMenu:ContextMenuBuiltInItems;
		public function Main() {
			init();
			
		}
		private function init():void{
			
			removeDefaultItems();
			addCustomMenuItems();
			
			}
		private function removeDefaultItems() {
			onMenu =  new ContextMenu();
			this.contextMenu=onMenu;
			onMenu.hideBuiltInItems();
			onBuiltMenu=onMenu.builtInItems;
			onBuiltMenu.print=true;//不需要时,可以把myBuiltMenu = myMenu.builtInItems;myBuiltMenu.print = true;注销掉
		}
		private function addCustomMenuItems() {

			var contextItem:ContextMenuItem=new ContextMenuItem("sinsoul",true);
			onMenu.customItems.push(contextItem);
			contextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openURL);
		}
		private function openURL(evt:ContextMenuEvent):void {

			navigateToURL(new URLRequest("http://www.cnblogs.com/sinsoul"));
		}
	}

}

 

posted @ 2010-11-14 16:47  sinsoul  阅读(1414)  评论(8编辑  收藏  举报