我多次查看代码,但无法弄清楚问题所需的帮助是代码;
menuItems = [{label:"60 Minutes View" , type:"radio", toggled:"true"},{label:"30 Minutes View" , type:"radio"},{label:"20 Minutes View" , type:"radio"},{label:"15 Minutes View" , type:"radio"},{label:"10 Minutes View" , type:"radio"},{label:"6 Minutes View" , type:"radio"},{label:"5 Minutes View" , type:"radio"}];
menu = Menu.createMenu( parentInstance, menuItems, false );
menu.addEventListener(MenuEvent.ITEM_CLICK,menuClick);
protected function menuClick(evt:MenuEvent):void
{
Alert.show("here is " + evt.item + " 23");
switch (evt.label)
{
case "60 Minutes View":
this.ChangeLayout(60);
break;
case "30 Minutes View":
this.ChangeLayout(30);
break;
case "20 Minutes View":
this.ChangeLayout(30);
break;
case "15 Minutes View":
this.ChangeLayout(15);
break;
case "10 Minutes View":
this.ChangeLayout(10);
break;
case "6 Minutes View":
this.ChangeLayout(6);
break;
case "5 Minutes View":
this.ChangeLayout(5);
break;
default:
break;
}//end switch
}//end function
但是甚至没有捕获项目点击事件。
答案 0 :(得分:2)
尝试将evt.item
/ evt.label
更改为evt.currentTarget.item
/ evt.currentTarget.label
或evt.target.item
/ evt.target.label
另外,只是一个建议,如果你为你的字符串对象创建常量,你的代码将更容易调试,因为拼写错误不会导致任何问题,并且除了允许你编辑你的编译器之外,编译器还会选择错误的常量字符串只有一次。
所以代替:
menuItems = [{label:"60 Minutes View" , type:"radio", toggled:"true"}];
switch (evt.currentTarget.label)
{
case "60 Minutes View":...
你可以创建一个常量:
private static const 60_MIN_VIEW:String = "60 Minutes View";
menuItems = [{label:60_MIN_VIEW , type:"radio", toggled:"true"}];
switch (evt.currentTarget.label)
{
case 60_MIN_VIEW:...