如何调用动态单选按钮中的功能?

发布于 2024-12-03 06:08:43 字数 1097 浏览 1 评论 0原文

我使用 XML 创建了一个测验应用程序。

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

和我的 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);
                    }       
                }

如何访问当前单选按钮来验证此答案?

示例图像

I have created a quiz app using XML.

My XML code:

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

    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?

Example Image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懒的傷心 2024-12-10 06:08:43

您可以使用 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);
}

You can use spark.components.RadioButtonGroup for that:

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文