1
votes

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

1
What is your item renderer extending? - The_asMan
EDIT: I'm using a itemRendererFunction that places a Label based on Data. ItemRenderers for labels are defined in declarations. - nbaztec

1 Answers

0
votes

Perhaps I'm misunderstanding what you're trying to do, but you shouldn't be calling your itemRendererFunction directly. You need to set the itemRendererFunction property of the DropDownList to your renderNode function, and let the DropDownList call it when it needs to.

Here is a basic example of how to use a itemRendererFunction:

http://blog.flexexamples.com/2009/03/19/using-a-custom-item-renderer-function-with-the-fxlist-control-in-flex-gumbo/

Cheers!