电竞比分网-中国电竞赛事及体育赛事平台

分享

AS3 右鍵菜單學(xué)習(xí)

 宜賓翠屏區(qū) 2018-12-24

與菜單相關(guān)的類一共有3個(gè)
ContextMenu類
ContextMenuBuiltInItems類  //與系統(tǒng)內(nèi)置菜單相關(guān)的類
ContextMenuItem類            //與用戶自定義菜單相關(guān)的類
flashcs3 新建一個(gè)元件,隨便畫(huà)個(gè)什么圖形。
吧元件拖動(dòng)到舞臺(tái)上,名稱改為mc
然后復(fù)制我下面的代碼到主時(shí)間軸第一偵

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)。
cm1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clickMenu);

cm2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clickMenu);

cm3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,clickMenu);
function clickMenu(e:ContextMenuEvent) {

 trace(e.bubbles);//false,是否冒泡
 trace(e.cancelable);//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

}

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多