0 Replies Latest reply on Aug 26, 2007 9:41 PM by aceinc

    Programmatically adding items to menubar

    aceinc
      I have a menubar that is created from an externally created xml stream. The structure looks like the following;

      <?xml version="1.0" encoding="iso-8859-1" ?>
      - <root>
      - <MenuItem label="File">
      <SubMenuItem label="Close All" value="CloseAll" type="FUNCTION" />
      <SubMenuItem label="Exit" value="Exit" type="FUNCTION" />
      <SubMenuItem label="Menu Reload" value="doMenuLoad" type="function" />
      </MenuItem>
      - <MenuItem label="Tools">
      - <MenuItem label="Search Tools">
      </MenuItem>
      - <MenuItem label="Anaysis Tools">
      </MenuItem>
      </MenuItem>
      - <MenuItem label="Window">
      - <MenuItem label="Styles">
      </MenuItem>
      </MenuItem>
      </root>

      (the leading hyphens were supplied by IE)

      After the menu has been created I want to add progarmmatically add menu items to the item labeled "Windows". I wrote the following code;

      private function addAppMenuItem(strParentLabel:String,strItemLabel:String,strItemValue:String,strItemType: String):void
      {
      trace(strParentLabel)
      var menu:XML = XML (AppMenu.dataProvider.getItemByAttribute("label",strParentLabel));
      trace("menu:"+menu);
      menu.appendChild(<MenuItem label="{strItemLabel}" value="{strItemValue}" type="{strItemType}"/>);
      trace("menu:"+menu);
      }

      addAppMenuItem("Window","Modules","","MENU"); //add menu item


      to do this, but it never finds "Windows" as you can see in the trace below;

      Window
      menu:
      menu:

      So I have two questions;

      1) How should I be doing this? I do want a generic module that can add menu items to any existing item based on its "value" attribute.

      2) If what I am doing is reasonable, what have I done wrong?

      Paul