自定义组件中的RadioButton功能

时间:2017-12-29 08:20:19

标签: flex actionscript mxml

我正在尝试创建一个包含图像和单选按钮的xmxl组件。 主应用程序脚本将使用其中几个组件。

我在尝试让RadioGroup正常运行时遇到问题。 我已在组件mxml文件中的RadioButton groupName属性上绑定了一个变量,因此我可以在主应用程序脚本中设置它。

这正常运行,因为当我通过每个RadioGroup选项卡时,只有每个组的第一个radiobutton获得焦点。 但是,当我单击组中的每个单选按钮时,前一个单选按钮不会取消选择。

我已经读过我无法绑定组件ID所以我怎样才能在每个组中只选择一个单选按钮? 我需要实现IFocusManager吗?

谢谢

1 个答案:

答案 0 :(得分:1)

每组RadioButton都需要一个分配给groupName的RadioButtonGroup。 RadioButtonGroup确保一次只选择1个按钮。 RadioButtonGroup在<fx:Declarations>中声明,并且是在groupName属性中分配的RadioButtonGroup的名称。

    <fx:Declarations>
        <s:RadioButtonGroup id="paymentType" itemClick="handlePayment(event);"/>
    </fx:Declarations>
    <s:VGroup paddingLeft="10" paddingTop="10">
        <s:RadioButton groupName="paymentType" 
                       id="payCheck" 
                       value="check" 
                       label="Pay by check" 
                       width="150"/>
        <s:RadioButton groupName="paymentType" 
                       id="payCredit" 
                       value="credit" 
                       label="Pay by credit card" 
                       width="150"/>
    </s:VGroup>

Apache Flex参考:http://flex.apache.org/asdoc/spark/components/RadioButtonGroup.html