Flex ActionScript 中的菜单项单击事件有问题吗?
我多次检查代码,但无法找出问题,这里需要的帮助是代码;
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
但它甚至没有捕获项目点击事件。
i go through the code several times but can not figure out the problem help required here is the code;
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
but is doesn't even capture the item click event .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将
evt.item
/evt.label
更改为evt.currentTarget.item
/evt.currentTarget.label
或evt.target.item
/evt.target.label
另外,只是一个建议,如果您为字符串对象创建常量,您的代码将更容易调试,因为什么都不会由拼写错误引起,编译器除了允许您只编辑一次字符串之外,还会识别出输入错误的常量。
而不是:
因此,您可以创建一个常量,
try changing
evt.item
/evt.label
toevt.currentTarget.item
/evt.currentTarget.label
orevt.target.item
/evt.target.label
also, just a suggestion, if you create constants for your string objects your code will be easier to debug as nothing will be caused by spelling mistakes and the compiler will pick up on a mistyped constant in addition to allowing you to edit your string only once.
so instead of:
you could create a constant: