0

假设我有 6 个广播组,例如:

<s:RadioButtonGroup id="radiogroup1"/>
<s:RadioButtonGroup id="radiogroup2"/>
<s:RadioButtonGroup id="radiogroup3"/>
<s:RadioButtonGroup id="radiogroup4"/>
<s:RadioButtonGroup id="radiogroup5"/>
<s:RadioButtonGroup id="radiogroup6"/>

如何使用 flash builder 对单选按钮值求和,并设置一些条件,例如如果分数 <10 - 在结果附近显示消息(分数差);如果分数>= 10(中等分数)?

4

2 回答 2

0

您可以为每个事件添加一个CHANGE事件,RadioButtonGroup以便在用户更改选择时收到通知。在事件处理程序中,汇总单选按钮组中的值并采取相应措施。

MXML:

<s:RadioButtonGroup id="radiogroup1" change="onRadioButtonChange"/>
<s:RadioButtonGroup id="radiogroup2" change="onRadioButtonChange"/>

然后在脚本块中:

private function onRadioButtonChange(event:Event):void
{
    var score:Number = 0;
    score += radioGroup1.selectedValue
    ...
}
于 2012-06-11T17:19:32.483 回答
0
        private function sumAll():void
        {
            var totalValue:Number;




            for each(var rbg:RadioButtonGroup in  [radiogroup1, radiogroup2, radiogroup3,radiogroup4, radiogroup5, radiogroup6])
            {
                totalValue+= rbg.selectedValue;  // if these are strings be sure to parseInt(rbg.selectedValue)
            }


            firstLabel.visible = firstLabel.includeInLayout = secondLabel.visible = secondLabel.includeInLayout = thirdLabel.visible = thirdLabel.includeInLayout = false;

            if(totalValue>10)
            {
                //Alert.show("You had more than 10");
                firstLabel.visible = firstLabel.includeInLayout = true;
            }
            else if(totalValue<=10 && totalValue>5)
            {
                //Alert.show("You passed");
                secondLabel.visible = secondLabel.includeInLayout = true;
            }
            else if(totalValue<=5)
            {
                //Alert.show("You failed");
                thirdLabel.visible = thirdLabel.includeInLayout = true;
            }
        }
    ]]>
</mx:Script>
<s:RadioButtonGroup id="radiogroup1"/>
<s:RadioButtonGroup id="radiogroup2"/>
<s:RadioButtonGroup id="radiogroup3"/>
<s:RadioButtonGroup id="radiogroup4"/>
<s:RadioButtonGroup id="radiogroup5"/>
<s:RadioButtonGroup id="radiogroup6"/>
<s:Label text="Winner winner chicken dinner" id="firstLabel" visible="false" includeInLayout="false"/>
<s:Label text="You passed" id="secondLabel" visible="false" includeInLayout="false"/>
<s:Label text="You failed" id="thirdLabel" visible="false" includeInLayout="false"/>
于 2012-06-11T17:20:15.123 回答