1 Reply Latest reply on Sep 18, 2007 4:33 PM by TeotiGraphix

    Building Menu

    wy790289
      Hi,

      I want to build a menu from XML data. The XML contains 2 values "label" and "act". The "label" will be the label field of the menu and the "act" will be the AC3 function name which will called when user click the corresponding menu item. I can get the value from the menu event function but how can I call the corresponding function retrieved from the XML?

      The XML file list here:
      <mx:XML format="e4x" id="mainMenu" xmlns="">
      <root>
      <menuitem label="File">
      <menuitemm label="Close" act="closeCurrentTab()" />
      </menuitem>
      <menuitem label="eForms">
      <menuitem label="User Requests" act="addUserRequest()"/>
      </menuitem>
      </root>
      </mx:XML>
      // end of XML

      which "addUserRequest()" and "closeCurrentTab()" are AC3 function defined in the program. I added the event handler when program initialized:

      myMenu.addEventListener(MenuEvent.ITEM_CLICK, menuFunc);

      The menuFunc will be the function to handle the item click event:

      private function menuFunc(event:MenuEvent):void {
      var mLabel:String;
      var mAct:String;

      mLabel = event.label;
      mAct = event.item.@act;

      }

      The variable "mAct" should store the function name to be calling. How can I call those function?

      Thanks a lot!
      Wilson

        • 1. Re: Building Menu
          TeotiGraphix Level 3
          Hi,

          I don't really know why you are putting parenthesis here.

          if act is supposed to mean action then, why not just go;

          <menuitem label="User Requests" act="addUserRequest"/>


          private function menuFunc(event:MenuEvent):void {
          var mLabel:String;
          var mAct:String;

          mLabel = event.label;
          mAct = event.item.@act;

          this[mAct]();
          }

          Peace, Mike