0 Replies Latest reply on Jun 18, 2007 10:05 AM by mightydev

    MenuBar insertChild

    mightydev
      i wanted to "insert items" into "Menu1" on the fly.
      The problem is when i insert some new menu items after clicked on "Add" button and click on menu "Menu1" , i see my items inserted.
      After, i clicked for 3 new items, and i dont see the 3 items on menu "menu1". Seem to me the MenuBar dont refresh or redraw with the dataprovider. When i trace my dataprovider for each insert, only dataprovider was updated everytime, but no MenuBar component !!!

      my sample code to underdtand my problem

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initCollections()">
      <mx:Script>
      <![CDATA[
      import mx.events.FlexEvent;
      import mx.events.MenuEvent;
      import mx.controls.menuClasses.MenuBarItem;

      private function addPatientMenuItem():void {


      var menu:XML = XML (mymenu.dataProvider.getItemAt(0));
      trace("menu:"+menu);
      menu.insertChildBefore(menu.children()[0],<menuitem label="Patient 1" type="normal" data="100"/>);
      trace("menu:"+menu);

      }

      import mx.events.MenuEvent;
      import mx.controls.Alert;
      import mx.collections.*;

      [Bindable]
      public var menuBarCollection:XMLListCollection;

      private var menubarXML:XMLList =
      <>
      <menuitem label="Menu1">
      <menuitem label="MenuItem 1-A" data="1A"/>
      <menuitem label="MenuItem 1-B" data="1B"/>
      </menuitem>
      <menuitem label="Menu2">
      <menuitem label="MenuItem 2-A" type="check" data="2A"/>
      <menuitem type="separator" />
      <menuitem label="MenuItem 2-B" >
      <menuitem label="SubMenuItem 3-A" type="radio"
      groupName="one" data="3A"/>
      <menuitem label="SubMenuItem 3-B" type="radio"
      groupName="one" data="3B"/>
      </menuitem>
      </menuitem>
      </>;

      // Event handler to initialize the MenuBar control.
      private function initCollections():void {
      menuBarCollection = new XMLListCollection(menubarXML);
      }

      ]]>
      </mx:Script>

      <mx:Panel title="MenuBar Control Example" height="75%" width="75%"
      paddingTop="10" paddingLeft="10">

      <mx:Label width="100%" color="blue"
      text="Select a menu item."/>

      <mx:MenuBar labelField="@label" dataProvider="{menuBarCollection}" id="mymenu"/>

      <mx:Button label="add" click="addPatientMenuItem()"/>

      </mx:Panel>
      </mx:Application>