AS3 - 获取上下文菜单选择

时间:2011-11-03 17:59:00

标签: actionscript-3

如何找出选择了哪个菜单项?

cm1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,changeColor);
cm2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,changeColor);

function changeColor(event:ContextMenuEvent):void{
trace("cm1 or cm2?")
}

感谢。

3 个答案:

答案 0 :(得分:0)

跟踪事件目标以找出当前目标(已点击)

function changeColor(event:ContextMenuEvent):void{
trace(event.currentTarget);
}

答案 1 :(得分:0)

function changeColor(event:ContextMenuEvent):void{
  if(event.target == cm1){
    //Do something
  } else if(event.target == cm2){
    //Do something
  }
}

答案 2 :(得分:0)

如果可能,请为每个上下文菜单元素添加单独的侦听器:

cm1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,changeColorCM1); cm2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,changeColorCM2);

function changeColorCM1(event:ContextMenuEvent):void {// CM1}

function changeColorCM2(event:ContextMenuEvent):void {// CM2}