自定义组件中的RadioButton功能

问题描述 投票:0回答:1

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

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

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

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

谢谢

flex actionscript mxml
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.