|
與菜單相關(guān)的類一共有3個(gè) var cm:ContextMenu=new ContextMenu(); //定義CM對(duì)象,賦值給可視元件. //而后的代碼中,會(huì)對(duì)cm的屬性進(jìn)行修改。達(dá)到自定義的效果 //那么就會(huì)分別對(duì)●內(nèi)置菜單 ●用戶菜單 進(jìn)行修改 mc.contextMenu=cm; //當(dāng)然你也可以賦值給舞臺(tái)。如下語(yǔ)句 //contextMenu=cm; /////////////編輯內(nèi)置菜單//////////////////////////////////////// cm.hideBuiltInItems();
////////////////////////////////////////////////////////////////////
////////////編輯用戶菜單//////////////////////////////////////// var cm1:ContextMenuItem=new ContextMenuItem("菜單1",false,true,true); var cm2:ContextMenuItem=new ContextMenuItem("菜單2",false,true,true); var cm3:ContextMenuItem=new ContextMenuItem("菜單3",false,false,true); cm.customItems.push(cm1);//標(biāo)題名字,分割線,可用,可見(jiàn) cm.customItems.push(cm2); cm.customItems.push(cm3); ////////////注意自定義菜單是可以在運(yùn)行中動(dòng)態(tài)修改的。看個(gè)人發(fā)揮了////////////
//////////////////////////偵聽(tīng)事件函數(shù)//////////////////////// //注意偵聽(tīng)的對(duì)象是ContextMenuItem,還有個(gè)MENU_SELECT事件的監(jiān)聽(tīng),注意那個(gè)是用在ContextMenu 上的 //在下面依次對(duì)cm1,cm2,cm3,三個(gè)ContextMenuItem對(duì)象添加偵聽(tīng)。 cm2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clickMenu); cm3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clickMenu); trace(e.bubbles);//false,是否冒泡 trace(e.contextMenuOwner);//[object MovieClip],所屬的對(duì)象 trace(e.currentTarget);//[object ContextMenuItem], trace(e.mouseTarget);//[object MovieClip],用戶右鍵單擊以顯示上下文菜單的顯示列表對(duì)象。 trace(e.target);//[object ContextMenuItem] trace(e.target.caption);//菜單1,可以從這里來(lái)判斷,后續(xù)操作或者應(yīng)該執(zhí)行的函數(shù)。 trace(e.currentTarget.caption);//菜單1 } |
|
|
來(lái)自: 宜賓翠屏區(qū) > 《ActionScprit3.0》