In Flex, sometimes when you need to clear a form you run into the problem that radio button groups seem to defy clearing: try as you might, setting selected=false on all buttons, setting selection=null on the group, doing both, doing them twice, etc., you always seem to end up with one pesky little radio button that's still selected. How do you solve this and restore the radio button group to its initial no-selection state?
The only way to solve this that I know of is to add a hidden dummy radio button that you select in order to deselect all the others.
Does this not work?
function clearRadioSelection(theGroup) {
theGroup.selection.selected = false;
theGroup.selectedRadio = undefined;
theGroup.dispatchEvent({type:"change"});
}
theGroup is the radio button group (not the individual radio buttons) from: http://kb2.adobe.com/cps/000/c4e4be2f.html
You could try setting all of your radio buttons to a RadioButtonGroup
then set RadioButtonGroup.selection to null
See http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html#includeExamplesSummary for reference on how to implement the RadioButtonGroup
control.
I believe you are using the RadiobuttonGroup and binding all the radiobutton controls for the perticular group.
So, easy way:
private function radioGroupReset():void
{
radioGroup1.selection = null;
}
This should work!
You need to group all of the radio buttons into a RadioButtonGroup and then set the group selection to null:
<mx:RadioButtonGroup id="myGroup" />
<mx:RadioButton label="One" groupName="myGroup" />
<mx:RadioButton label="Two" groupName="myGroup" />
<mx:RadioButton label="Three" groupName="myGroup" />
<mx:Button label="Clear" click="myGroup.selection = null;" />
Obviously the previous answers should get you where you're going in the cleanest way, but if you're hitting your head against the wall, just collect all your radio buttons into a component and then redraw the entire component when you need to clear it. Problem solved.
Forms are gimpy at best anyway. No need to make life too hard.
Simply set the selection property of the radioButtonGroup to null and the it'll go to its initial condition.
e.g, if
<mx:RadioButtonGroup id="answers" />
then writing the following line in ActionScript
answers.selection = null;
would reset the group with no radio button selected left. Hope it helps you. I took the idea from following link. Best of luck.
http://blog.flexexamples.com/2008/01/06/clearing-a-selected-radiobutton-control-in-flex/