views:

169

answers:

2

Hi, I'm working on Flash Builder with latest flex SDK.

I have a problem getting the value radioButton of the selceted radio button inside a form:

<mx:Form id="form_new_contribution"> 
 <mx:FormItem label="Contribution type" includeIn="project_contributions">
  <mx:RadioButtonGroup id="myG" enabled="true" />
  <mx:RadioButton id="subtitle" label="subtitle" groupName="{myG}" value="subtitle"/>
  <mx:RadioButton id="note" label="notes / chapters" groupName="{myG}" value="note"/>
 </mx:FormItem>
</mx:Form>

the function is:

protected function button_add_new_clickHandler(event:MouseEvent):void{
 Alert.show(myG.selectedValue.toString());
}

I tried also:

Alert.show(myG.selection.toString());

bothe codes show error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

and if It only works if I put :

Alert.show(myG.toString());

it alerts : Object RadioButtonGroup

thanx for any hints, and sorry for the long message :)

A: 

The only thing I see wrong here is that the groupName property of RadioButton is a string, not a curly-braced reference to a RadioButtonGroup.

You should render it as:

 <mx:RadioButton id="subtitle" label="subtitle" groupName="myG" value="subtitle"/>

not

 <mx:RadioButton id="subtitle" label="subtitle" groupName="{myG}" value="subtitle"/>

Or you can also use the group property with an RBG reference:

 <mx:RadioButton id="subtitle" label="subtitle" group="{myG}" value="subtitle"/>
Robusto
thank you Robusto,Your second solution worked just perfectly; I changed "groupName" to "group" and it worked!thank you guys ;)
numediaweb
A: 

When are you calling this alert function? Is it possible that neither of the radio buttons are selected when the alert is called, thus selection and selectedValue are accurately returned as null?

quoo
That was my first thought, until I saw the issue with the groupName.
Robusto
no, it has nothing to do with selecting the buttons, I even added the property selected="true" to the first radio button.thank you
numediaweb