1

我正在使用最新的 flex SDK 开发 Flash Builder。

我在获取表单中选择的单选按钮的值 radioButton 时遇到问题:

<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

感谢您的任何提示,对于长消息表示抱歉:)

4

2 回答 2

2

我在这里看到的唯一错误是groupNameRadioButton 的属性是一个字符串,而不是对 a 的花括号引用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"/>
于 2010-05-13T16:53:57.143 回答
0

你什么时候调用这个警报函数?是否有可能在调用警报时没有选择任何一个单选按钮,因此 selection 和 selectedValue 准确地返回为 null?

于 2010-05-13T17:23:27.523 回答