I have created a quiz app using XML.
我使用XML创建了一个测验应用程序。
My XML code:
我的XML代码:
<item>
<question type="singleChoice">
<![CDATA[1.What does CSS stand for?]]>
</question>
<answer correct="yes">Cascading Style Sheets</answer>
<answer>Computer Style Sheets</answer>
<answer>Colorful Style Sheets</answer>
<answer>Creative Style Sheets</answer>
</item>
and my flex Script code:
和我的flex脚本代码:
protected function buildQuestion():void {
var question:XML=XML(xmlList[quizIndex])
answerOption.removeAllElements()
if(question.question.@type == SINGLE_CHOICE)
{
for each(var tempxml:XML in question.answer)
{
var rad:RadioButton= new RadioButton();
rad.label=tempxml[0];
answerOption.addElement(rad);
}
}
How can I access the current radio button to validate this answer?
如何访问当前单选按钮以验证此答案?
1 个解决方案
#1
1
You can use spark.components.RadioButtonGroup
for that:
您可以使用spark.components.RadioButtonGroup:
protected function buildQuestion():void
{
var question:XML = XML(xmlList[quizIndex]);
answerOption.removeAllElements();
if (question.question.@type == SINGLE_CHOICE)
{
var group:RadioButtonGroup = new RadioButtonGroup();
group.addEventListener(Event.CHANGE, onAnswerChanged);
for each(var tempxml:XML in question.answer)
{
var rad:RadioButton = new RadioButton();
rad.label = tempxml[0];
rad.group = group;
rad.value = tempxml[0];
answerOption.addElement(rad);
}
}
}
private function onAnswerChanged(event:Event):void
{
var group:RadioButtonGroup = RadioButtonGroup(event.currentTarget);
trace ("Selected answer: " + group.selectedValue);
}
#1
1
You can use spark.components.RadioButtonGroup
for that:
您可以使用spark.components.RadioButtonGroup:
protected function buildQuestion():void
{
var question:XML = XML(xmlList[quizIndex]);
answerOption.removeAllElements();
if (question.question.@type == SINGLE_CHOICE)
{
var group:RadioButtonGroup = new RadioButtonGroup();
group.addEventListener(Event.CHANGE, onAnswerChanged);
for each(var tempxml:XML in question.answer)
{
var rad:RadioButton = new RadioButton();
rad.label = tempxml[0];
rad.group = group;
rad.value = tempxml[0];
answerOption.addElement(rad);
}
}
}
private function onAnswerChanged(event:Event):void
{
var group:RadioButtonGroup = RadioButtonGroup(event.currentTarget);
trace ("Selected answer: " + group.selectedValue);
}