Actionscript 3 Flex radioButton通过ActionScript设置选定值

Actionscript 3 Flex radioButton通过ActionScript设置选定值,actionscript-3,apache-flex,actionscript,Actionscript 3,Apache Flex,Actionscript,我在列表组件的ItemRenderer中有一个单选按钮。我试图根据数据提供者(SchoolList.Athletics\u Fav)中的字段设置每个单选按钮的选定值 这些轨迹显示正确的值: 跟踪(“值:+value.Athletics\u Fav2”); 跟踪(“selectText:+selectText”) 这个不是。 跟踪(“BTSELECT:+radBtnPhone.selected”) 有人对我如何将radBtnPhone.selected设置为数据提供程序值(SchoolList.A

我在列表组件的ItemRenderer中有一个单选按钮。我试图根据数据提供者(SchoolList.Athletics\u Fav)中的字段设置每个单选按钮的选定值

这些轨迹显示正确的值: 跟踪(“值:+value.Athletics\u Fav2”); 跟踪(“selectText:+selectText”)

这个不是。 跟踪(“BTSELECT:+radBtnPhone.selected”)

有人对我如何将radBtnPhone.selected设置为数据提供程序值(SchoolList.Athletics\u Fav)有什么建议吗?任何帮助都将不胜感激

代码:
]>

试试这个:

<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
    >

  <s:SkinnableDataContainer>
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
    <mx:ArrayList id="SchoolList">
        <fx:Object SchoolName="Smith" Athletics_Fav="true" SchoolImage="./SchoolImage.png"/>
        <fx:Object SchoolName="Jones" Athletics_Fav="false" SchoolImage="./SchoolImage.png"/>
        <fx:Object SchoolName="Davis" Athletics_Fav="false" SchoolImage="./SchoolImage.png"/>
        <fx:Object SchoolName="Cooper" Athletics_Fav="true" SchoolImage="./SchoolImage.png"/>
    </mx:ArrayList>
    <s:itemRenderer>
        <fx:Component>
            <s:ItemRenderer>
            <s:Group width="100%" height="100%">
                <s:Rect width="100%" height="100%">
                    <s:fill><s:SolidColor color="0xffffff" /></s:fill>
                </s:Rect>
                <s:Line width="100%">
                    <s:stroke>
                        <s:SolidColorStroke weight="1" color="0xd3d3d3"/>
                    </s:stroke>
                </s:Line>

            <s:HGroup id="bigGrpPhone" width="100%" verticalAlign="middle">
                <s:HGroup id="grpPhone" gap="6" height="100%" width="95%" paddingLeft="2" paddingRight="2" paddingTop="2" verticalAlign="middle">
                    <s:BitmapImage id="imgPhone" source="{data.SchoolImage}" width="70" height="70" />
                    <s:Label id="schlNamePhone" maxDisplayedLines="1" width="100%" height="100%" text="{data.SchoolName}" verticalAlign="middle"/>
                </s:HGroup>
                <s:HGroup width="5%" horizontalAlign="center" verticalAlign="middle">
                    <s:RadioButton width="50" id="radBtnPhone" styleName="myRadioButton" selected="{data.Athletics_Fav}"/>
                </s:HGroup>
            </s:HGroup>
            </s:Group>
            </s:ItemRenderer>
        </fx:Component>
    </s:itemRenderer>
  </s:SkinnableDataContainer>
</s:Application>


我想出了一个简单的解决方案,想在这里发布给其他可能需要它的人。我创建了一个布尔变量(btnPhValue),并根据我的SchoolList数组中field AthleticsFavs的值设置它的值。然后我将radioButton.selected值设置为我创建的布尔变量。很好用

<s:List id="phoneList" width="100%" height="100%" contentBackgroundColor="0x0065a4" fontSize="20"
            dataProvider="{SchoolList}"  >
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer >
                    <fx:Script>
                        <![CDATA[
                            override public function set data(value:Object):void 
                            {
                                super.data = value;
                                var selectPhText = value.AthleticsFavs;
                                var btnPhValue:Boolean;
                                radBtnPhone.group=outerDocument.radGrp;
                                if (selectPhText == 1)
                                    btnPhValue = true;
                                    else 
                                    btnPhValue = false;
                                radBtnPhone.selected = btnPhValue;
                            }
                        ]]>
                    </fx:Script>
                    <s:Group width="100%" height="100%">
                        <s:Rect width="100%" height="100%">
                            <s:fill><s:SolidColor color="0xffffff" /></s:fill>
                        </s:Rect>
                        <s:Line width="100%">
                            <s:stroke>
                                <s:SolidColorStroke weight="1" color="0xd3d3d3"/>
                            </s:stroke>
                        </s:Line>
                    </s:Group>
                    <s:HGroup id="bigGrpPhone" width="100%" verticalAlign="middle">
                        <s:HGroup id="grpPhone" gap="6" height="100%" width="95%" paddingLeft="2" paddingRight="2" paddingTop="2" verticalAlign="middle">
                            <s:BitmapImage id="imgPhone" source="{data.SchoolImage}" width="70" height="70" />
                            <s:Label id="schlNamePhone" maxDisplayedLines="1" width="100%" height="100%" text="{data.SchoolName}" verticalAlign="middle"/>
                        </s:HGroup>
                        <s:HGroup width="5%" horizontalAlign="center" verticalAlign="middle">
                            <s:RadioButton width="50" id="radBtnPhone" styleName="myRadioButton" /> 
                            <!-- <MyComp:myRadioButton width="50" id="radBtnPhone" styleName="myRadioButton" /> -->
                        </s:HGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
    </s:List>

尝试listId.selectedItem.radBtnPhone.selected
<s:List id="phoneList" width="100%" height="100%" contentBackgroundColor="0x0065a4" fontSize="20"
            dataProvider="{SchoolList}"  >
        <s:itemRenderer>
            <fx:Component>
                <s:ItemRenderer >
                    <fx:Script>
                        <![CDATA[
                            override public function set data(value:Object):void 
                            {
                                super.data = value;
                                var selectPhText = value.AthleticsFavs;
                                var btnPhValue:Boolean;
                                radBtnPhone.group=outerDocument.radGrp;
                                if (selectPhText == 1)
                                    btnPhValue = true;
                                    else 
                                    btnPhValue = false;
                                radBtnPhone.selected = btnPhValue;
                            }
                        ]]>
                    </fx:Script>
                    <s:Group width="100%" height="100%">
                        <s:Rect width="100%" height="100%">
                            <s:fill><s:SolidColor color="0xffffff" /></s:fill>
                        </s:Rect>
                        <s:Line width="100%">
                            <s:stroke>
                                <s:SolidColorStroke weight="1" color="0xd3d3d3"/>
                            </s:stroke>
                        </s:Line>
                    </s:Group>
                    <s:HGroup id="bigGrpPhone" width="100%" verticalAlign="middle">
                        <s:HGroup id="grpPhone" gap="6" height="100%" width="95%" paddingLeft="2" paddingRight="2" paddingTop="2" verticalAlign="middle">
                            <s:BitmapImage id="imgPhone" source="{data.SchoolImage}" width="70" height="70" />
                            <s:Label id="schlNamePhone" maxDisplayedLines="1" width="100%" height="100%" text="{data.SchoolName}" verticalAlign="middle"/>
                        </s:HGroup>
                        <s:HGroup width="5%" horizontalAlign="center" verticalAlign="middle">
                            <s:RadioButton width="50" id="radBtnPhone" styleName="myRadioButton" /> 
                            <!-- <MyComp:myRadioButton width="50" id="radBtnPhone" styleName="myRadioButton" /> -->
                        </s:HGroup>
                    </s:HGroup>
                </s:ItemRenderer>
            </fx:Component>
        </s:itemRenderer>
    </s:List>