0

我有以下弹性组件:

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx" 
         width="400" 
         height="300"
         borderColor.male="blue"
         borderColor.female="#FF00F6"
         initialize="init(event)">

    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            protected function genderChanged(event:Event):void
            {               
                setByRadioGroup();
            }

            protected function init(event:FlexEvent):void
            {
                currentState = "male";
                //setByRadioGroup()
            }

            protected function setByRadioGroup():void {
                currentState = genderGroup.selectedValue as String;
            }

        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:RadioButtonGroup id="genderGroup" change="genderChanged(event)">

        </s:RadioButtonGroup>
    </fx:Declarations>
    <s:states>
        <s:State name="male"/>
        <s:State name="female"/>
    </s:states>
    <s:Form>
        <s:FormItem label="name">
            <s:TextInput name="nameField" id="nameField"/>
        </s:FormItem>
        <s:FormItem label="gender">
            <s:RadioButton label="male" groupName="genderGroup" selected.male="true"/>
            <s:RadioButton label="female" groupName="genderGroup" selected.female="true"/>
        </s:FormItem>
    </s:Form>
</s:BorderContainer>

我试图通过将 currentState 设置为“male”来初始化组件的整个状态(包括选定的单选按钮)。这最初有效(选择了正确的单选按钮并且边框为蓝色): 初始状态

但是当我单击另一个单选按钮时,用户界面有时会处于奇怪的状态 - 单选选择恢复为原始状态,但边框颜色会发生变化: 点击后

我错过了某种比赛吗?

我正在使用 flex 4.6.0 和 flash builder 4.7

4

1 回答 1

1

您还必须告知其他状态的选定值,因为它可以按预期工作:

<s:RadioButton label="male" groupName="genderGroup" selected.male="true" selected.female="false"/>
<s:RadioButton label="female" groupName="genderGroup" selected.female="true" selected.male="false"/>

虽然我宁愿不使用状态标识符设置选定的值。我会在组件中添加一个状态更改侦听器,并在其处理函数中设置选定的值。但这只是个人的选择......

于 2013-03-03T11:09:24.587 回答