一直没研究过右键功能,也因为一直不曾有这个需求,但是今天既然看到了这个效果,就收藏一下,以备不时之需。
// ActionScript 3.0 var red_cmi:ContextMenuItem = new ContextMenuItem("red"); red_cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, cmi_menuItemSelect); var cm:ContextMenu = new ContextMenu(); cm.customItems.push(red_cmi); cm.hideBuiltInItems(); var spr:Sprite = new Sprite(); spr.contextMenu = cm; spr.graphics.beginFill(0x000000); spr.graphics.drawRect(0, 0, 120, 90); spr.graphics.endFill(); spr.x = 10; spr.y = 10; addChild(spr); function cmi_menuItemSelect(evt:ContextMenuEvent):void { spr.graphics.clear(); spr.graphics.beginFill(0xFF0000); spr.graphics.drawRect(0, 0, 120, 90); spr.graphics.endFill(); }