我有以下flex组件:
<?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”来初始化组件的整个状态(包括选定的单选按钮)。这最初工作(选择正确的单选按钮,边框为蓝色):
但是当我点击另一个单选按钮时,ui有时会以奇怪的状态结束 - 无线电选择会恢复为原始状态,但边框颜色会发生变化:
这里有某种种族缺失吗?
即时使用flex 4.6.0和flash builder 4.7
答案 0 :(得分: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"/>
虽然我不想用状态标识符设置所选值。 我将在组件中添加状态更改侦听器,并在其处理函数中设置所选值。 但这只是个人选择......