views:

13

answers:

2

I have an arrayCollection with strings in them, is there some way I can databind a RadioButtonGroup to the array collection? As we can do for combo boxes

var cBox:ComboBox = new ComboBox();
cBox.dataProvider = arrayCollection;

There is no RadioButtonGroup.dataprovider property. I know this has to be done manually, what is the most efficient way to do this?

+1  A: 

you will need to manually create and add the radio buttons to your container ( with AS3 ) .

for each(var itemStr:String in array) 
{
    var rb:RadioButton = new RadioButton();
    rb.id = itemStr;
    rb.label = itemStr;

    container.addChild(rb); 
}
Adrian Pirvulescu
There is a problem with this approach, when the collection changes the radio buttons are not recreated, since there is no binding. If instead of radio buttons I had a comboBox databound to the array then I wont have to do anything if the array changes. The changes will automatically be shown in the comboBox.
Arslan
You can use a setter function for passing the array and each time you call the setter you remove all old radiobuttons and add new ones that fit the new array. After all this is what binding is about: detecting changes and acting in consequence.
Adrian Pirvulescu
A: 

Or use a Repeater for the RadioButtons, all part of the same group.

Gregor Kiddie