After much chagrin, I finally discovered the solution to a problem I was having last night. Here's the scenario, I have a data set that is being returned in deeply nested XML and from that set I am wanting to create several groups of radiobuttons that will act as filters for an e4x expression. The issue is that I can not rely on specific values from the xml (since I don't know what they are going to be at runtime). Additionally, I do not know that the values of the xml are going to be consistent across subnodes. Let me give an example:
<?xml version="1.0"?>
<root>
<role idRole="1" roleName="Individual">
<type idType="1" typeName="yearly">
<data idData="123" name="Apples" value="50"/>
<data idData='234" name="Oranges" value="75"/>
</type>
<type idType="2" typeName="monthly">
<data idData="345" name="Apples" value="10"/>
<data idData="456" name="Oranges" value="15"/>
</type>
</role>
<role idRole="2" roleName="Company">
<type idType="3" value="daily">
<data idData="900" name="Apples" value="5"/>
<data idData="901" name="Oranges" value="3"/>
</type>
<type idType="1" value="yearly">
<data idData="567" name="Apples" value="500"/>
<data idData="678" name="Oranges" value="1000"/>
</type>
</root>
Ok, now what we have is a dataset that might return different values depending on the individual nested nodes and so when the user selectes a role, we want the radiobuttons in the second group to reflect the values that are available for that role.
So we first begin by creating our XML:
<mx:XML id="coll" source="myData.xml"/>
Now the first group:
<mx:RadioButtonGroup id="grpRole"/>
<mx:Repeater id="rptRole" dataProvider="{coll..role}">
<mx:RadioButton groupName="grpRole" label="{rptRole.currentItem.@roleName}" value="{rptRole.currentItem.@idRole}"/>
//We can also pass the entire object into the radiobutton's data property if we want by setting data="{rptRole.currentItem}", but there is no need for that here.
</mx:Repeater>
Now the second group of radiobuttons:
<mx:RadioButtonGroup id="grpType"/>
// Now this repeater needs to know which role we are referencing from the first set of radiobuttons, but we can't necessarily use any specific value so instead, we can get around this by using an index of the selection property from the radiobuttongroup.I tried to use the grpRole.selection.parent.currentIndex at first but that doesnt work. Instead, you can access the repeaterIndex directly from the selection object.
<mx:Repeater id="rptType" dataProvider="{coll..role[grpRole.selection.repeaterIndex].type}">
<mx:RadioButton groupName="grpRole" label="{rptType.currentItem.@value}" value="{rptType.currentItem.@idType}"/>
//We can also pass the entire object into the radiobutton's data
property if we want by setting data="{rptType.currentItem}", but there
is no need for that here.
</mx:Repeater
Now, when our user selects a value in the first radiobuttongroup, the second group will automatically update to display the available options.