You are here

RadioButtonGroup inside of Repeater

See the Update before you look at this.

If you've ever tried to use repeater to create radiobutton groups, you probably found that setting the ID doesn't work and the group won't initialize. That's because flex wants "visual" objects in the repeater. To fix this problem, you simply create the groups before you repeat like so.
<mx:Script>
  <![CDATA[
   import mx.controls.RadioButtonGroup;
   import mx.collections.ArrayCollection;
   [Bindable] 
   private var rbGroups:ArrayCollection;
   
   private function createRBGroups():void{
    rbGroups= new ArrayCollection();   
    var rbGroup:RadioButtonGroup;
    for each(var item:Object in someRepeater.dataProvider as ArrayCollection){
     rbGroup = new RadioButtonGroup();
     rbGroups.addItem(rbGroup);
    }
   }
  ]]>
</mx:Script>
<mx:Repeater repeatStart="createRBGroups()" id="someRepeater">
<mx:HBox>   
  <mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>
  <mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>
  <mx:RadioButton group="{RadioButtonGroup(rbGroups.getItemAt(someRepeater.currentIndex))}"/>   
   
 </mx:HBox>
</mx:Repeater>
category: