Wednesday, April 15, 2009

Radio Button Binding in Flex

How do we bind a radio button group to an XML ? Not all that straightforward in Flex. But not that difficult either.

What you need to do is to make use of the Repeater Control. Check out the following code.

private var treeData:XML =
<Question Label="This is Question 1">
<Option Label="This is option one"/>
<Option Label="This is option one 2"/>
<Option Label="This is option one 3"/>
<Option Label="This is option one 4"/>

<mx:Repeater dataProvider="{treeData.Question.Option}" id="repeater1">
<mx:RadioButton label="{repeater1.currentItem.@Label}" width="201" groupName="radioBtnGroup"/>

That's all you need. :)