0
votes

Working in Flex 3, I have a series of components being rendered on a canvas, each of which should represent a single potential selection, ideally in a RadioButtonGroup. So in my parent canvas I am defining the RadioButtonGroup, and each component provides a single RadioButton. However, this doesn't seem to work.

Suppose there is a component called aComponent defined as such:

<mx:Canvas ...>
 ...
 <mx:RadioButton id="someButton" groupName="myRadioButtonGroup" ... />
</mx:Canvas>

The outer canvas:

<mx:Canvas id="outerCanvas" ...>
 ...
 <mx:Script>
   public function doesSomething():void
   {
     var myComponent:aComponent = new aComponent();
     outerCanvas.addChild(myComponent);    
   }
 </mx:Script>
 ...
 <mx:RadioButtonGroup id="myRadioButtonGroup" />
</mx:Canvas>

So my guess was that at this point if, say, four of these components were added, the radio buttons would behave in mutually exclusive fashion and I'd be able to access myRadioButtonGroup.selectedValue to get the current selection. However, it doesn't seem to work that way.

Is what I'm trying to do even possible, or have I maybe just missed something?

Thanks!

1

1 Answers

0
votes

Edit - got to the bottom of it:

The radiobuttongroup isn't available to the component. It's parent has 'myRadioButtonGroup', but not the component.. Pass the 'myRadioButtonGroup' to the constructor and use it..

outerCanvas function:

var myComponent:aComponent = new aComponent(myRadioButtonGroup);

aComponent definition:

private var radioGroup:RadioButtonGroup;
function aComponent(radioGroup:RadioButtonGroup):void {
  this.radioGroup = radioGroup;
}
</mx:Script>
<mx:RadioButton id="someButton" groupName="radioGroup" ... />

untested, but hopefully gives you the idea