简体   繁体   English

带有状态和单选按钮的奇怪的flex行为

[英]weird flex behaviour with states and radio buttons

i have the following flex component: 我有以下弹性组件:

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

im trying to get the entire state of the component (incl. selected radio button) to initialize by setting the currentState to "male". 我试图通过将currentState设置为“ male”来获取要初始化的组件的整个状态(包括选中的单选按钮)。 this works initially (correct radio button is selected and border is blue): 最初可以正常工作(选择了正确的单选按钮,边框为蓝色): 初始状态

but when i click the other radio button the ui sometimes ends up in a weird state - the radio selection reverts back to the original but the border color changes: 但是,当我单击另一个单选按钮时,UI有时会以一种怪异的状态结束-单选会恢复为原始状态,但边框颜色会更改: 点击后

is there some sort of race here im missing? 我是否缺少某种种族?

im using flex 4.6.0 and flash builder 4.7 即时通讯使用Flex 4.6.0和Flash Builder 4.7

You have to tell the selected value for the other state as well for that it works like expected: 您还必须告诉其他状态所选择的值,因为它的工作方式与预期的一样:

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

Though I would rather not set the selected values with the state identifier. 虽然我宁愿不使用状态标识符设置所选值。 I would add a state change listener in the component and set the selected values in its handler function. 我将在组件中添加状态更改侦听器,并在其处理函数中设置选定的值。 But this is only a personal choice.... 但这只是个人选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM