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

    Programmatically adding items to menubar

    aceinc Level 1
      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 label="Tools">
      - <MenuItem label="Search Tools">
      - <MenuItem label="Anaysis Tools">
      - <MenuItem label="Window">
      - <MenuItem label="Styles">

      (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
      var menu:XML = XML (AppMenu.dataProvider.getItemByAttribute("label",strParentLabel));
      menu.appendChild(<MenuItem label="{strItemLabel}" value="{strItemValue}" type="{strItemType}"/>);

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

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


      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?