Flex ActionScript 中的菜单项单击事件有问题吗?

发布于 2024-10-01 11:08:19 字数 1191 浏览 2 评论 0原文

我多次检查代码,但无法找出问题,这里需要的帮助是代码;

 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

子栖 2024-10-08 11:08:19

尝试将 evt.item / evt.label 更改为 evt.currentTarget.item / evt.currentTarget.labelevt.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:...

try changing evt.item / evt.label to evt.currentTarget.item / evt.currentTarget.label or evt.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:

menuItems = [{label:"60 Minutes View" , type:"radio", toggled:"true"}];

switch (evt.currentTarget.label)
       {
       case "60 Minutes View":...

you could create a constant:

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:...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文