给SP添加 自定义右键菜单比较符合

package  {
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.events.ContextMenuEvent;  
      import flash.net.URLRequest;  
       import flash.ui.ContextMenu;  
            import flash.ui.ContextMenuBuiltInItems;  
            import flash.ui.ContextMenuItem; 
            import flash.net.navigateToURL; 
	public class Main extends MovieClip {
		
      /*      
        *author : SinSoul     
        *blogs: http://www.cnblogs.com/sinsoul
          */
      
 
		private var onMenu:ContextMenu;  
                private var onBuiltMenu:ContextMenuBuiltInItems; 
		private var contextItem:ContextMenuItem;
		
		public function Main() {
			// constructor code
			init();
			removeDefaultItems(); 
		}
		private function init():void
		{
			removeDefaultItems();
			mc.addEventListener(MouseEvent.MOUSE_MOVE, onmcMoveHandler);
			mc1.addEventListener(MouseEvent.MOUSE_MOVE, onMc1MoveHandler);
			mc2.addEventListener(MouseEvent.MOUSE_MOVE, onMc2MoveHander);
		}
		private function onmcMoveHandler(e:MouseEvent):void
		{
			
			trace(1);
			removeDefaultItems();
			contextItem = new ContextMenuItem("sinsoul", true);  
			 contextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openURL); 
            onjinruHandler();
		}
		private function onMc1MoveHandler(e:MouseEvent):void
		{
			removeDefaultItems();
			//var contextItem:ContextMenuItem=new ContextMenuItem("孩子",true);  
			contextItem = new ContextMenuItem("孩子", true);
            //onMenu.customItems.push(contextItem);  
            contextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openURL1); 
			onjinruHandler();
		}
		private function onMc2MoveHander(e:MouseEvent):void
		{
			removeDefaultItems();
			//var contextItem:ContextMenuItem=new ContextMenuItem("老子",true); 
			contextItem = new ContextMenuItem("老子", true);
            //onMenu.customItems.push(contextItem);  
            contextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openURL2); 
			onjinruHandler();
		}
		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 openURL(evt:ContextMenuEvent):void
		{   
			navigateToURL(new URLRequest("http://www.cnblogs.com/sinsoul"));  
        }
		private function openURL1(evt:ContextMenuEvent):void
		{   
			navigateToURL(new URLRequest("http://www.baidu.com"));  
        }
		private function openURL2(evt:ContextMenuEvent):void
		{   
			navigateToURL(new URLRequest("http://www.qq.com"));  
        }
		private function onjinruHandler():void
		{
			onMenu.customItems.push(contextItem);  
            //contextItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, openURL);
		}


	}
	
}

posted @ 2011-04-25 11:07  sinsoul  阅读(395)  评论(0编辑  收藏  举报