用as3做右键版权

介绍如何使用as3创建右键菜单

[code]

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")
  }
 }
}

[/code]

使用方法:

import fb.copyright.*
var cr:Copyright=new Copyright(this)

posted @ 2008-10-23 10:15  Landy_di  阅读(169)  评论(0)    收藏  举报