2010-05-13 62 views
1

我正在使用最新的flex SDK开发Flash Builder。Flex;在FormItem中获取RadioButton的值

我有得到的selceted单选按钮的值单选按钮形式内部的问题:

<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> 

的功能是:

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

我试图也:

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

显示错误代码:

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

,如果它只能如果我把:

Alert.show(myG.toString()); 

它提醒:对象的RadioButtonGroup

thanx的任何提示,并遗憾的长消息:)

回答

2

唯一我在这里看到的错误是RadioButton的groupName属性是一个字符串,而不是对RadioButtonGroup的卷曲引用。

你应该呈现为:

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

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

或者你也可以使用group属性与RBG参考:

<mx:RadioButton id="subtitle" label="subtitle" group="{myG}" value="subtitle"/> 
+0

谢谢罗布斯托, 你的第二个解决方案工作完美;我将“groupName”更改为“group”,它工作正常! 谢谢大家;) – numediaweb 2010-05-14 10:57:48

0

当你调用这个警报功能?当警报被调用时,是否有可能没有选择任何单选按钮,因此selection和selectedValue被精确地返回为null?

+0

这是我的第一个想法,直到我看到groupName的问题。 – Robusto 2010-05-13 17:52:19

+0

不,它与选择按钮无关,我甚至将属性selected =“true”添加到第一个单选按钮。 谢谢 – numediaweb 2010-05-14 10:56:24