2010-05-13 48 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