0 Replies Latest reply on Mar 18, 2011 5:31 AM by nbaztec

    Add items to DropDownList using ItemRenderer

    nbaztec

      I have a XML structure like:

       

      <Main>
        <Category1>
          <Data Name="Data1">
            <Item>
              <Name>foo</Name>
              <Info>bar</Info>
            </Item>
            <Item>
              <Name>baz</Name>
              <Info>FOO</Info>
            </Item>
          </Data>
          <Data Name="Data2">
          </Data>
        </Category1>
        <Category2>
          </Category2>
      </Main>
      

       

      I use a custom DropDownList to populate it using an ItemRendererFunction:

      <s:Label text="{data.attribute('Name')}" top="3" left="10" right="10" bottom="3" color="0xFF00FF" />

      if it has an attribute 'Name', else a regular Label.

      Render function is :

      public function renderNode(item:*):IFactory
      {
          if (item.attribute('Name') != null)
              return new ClassFactory(SpecialItemRenderer);
          else
              return new ClassFactory(RegularItemRenderer);
      }

       

      However, I specify the XML in the form of a dataProvider, as dProv.child('Category1'), hence I only get the 2 <Data> nodes in the renderNode(). But I also want to populate the <Item> nodes at the same time.

      I've tried using a loop using a new itemRendererFunction

       

      newFunc(item:*):void:
      {
        var nodes:XMLNode = item.children();
        while(nodes)
        {
            this.renderNode(nodes);
            nodes = nodes.nextSibling;
        } 
      
      }
      but got a runtime error as the newFunc() wouldn't be returning anything.
      

       

       

      Then I made changes to the original renderNode() by creating a mx:Label item dynamically & adding it

      to this via this.addElement(newLabel) but this wouldn't place the Label in the drop down list, but on top of the control.

       

      So I'd like to know is there any way I can add these Items/label dynamically while parsing the original XML Data?

       

      Regards,
      Nisheeth Barthwal