如何使用微调器列表访问Adobe Air中的选定项目?

时间:2012-02-21 23:52:17

标签: flex list air adobe spinner

我正在学习Adobe Air,并且希望在我创建的微调器列表中获取当前所选项目,但是每次使用 selectedItem 时,我都会一遍又一遍地获得相同的值,无论如何选项我选择。我正在尝试为Playbook创建一个应用程序,这是我的SpinnerList代码:

<s:SpinnerListContainer x="10" y="279" width="325" height="266">
    <s:SpinnerList width="69" height="100%" enabled="true" labelField="data" selectedIndex="1" id="From">
        <s:ArrayList>
            <fx:Object data="Time"></fx:Object>
            <fx:Object data="KM"></fx:Object>
            <fx:Object data="Miles"></fx:Object>
        </s:ArrayList>
    </s:SpinnerList>
</s:SpinnerListContainer>

无论如何,“KM”始终显示为所选项目。这就是我在脚本标签中的内容:

var selected = From.selectedItem;

我该如何解决这个问题? 谢谢

1 个答案:

答案 0 :(得分:1)

使用4.6 SDK这对我有用:

<?xml version="1.0" encoding="utf-8"?>
<s:View title="HomeView"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
        <![CDATA[
            import spark.events.IndexChangeEvent;

            protected function From_changeHandler(event : IndexChangeEvent) : void
            {
                somewhereToDisplaySelected.text = From.selectedItem.data;
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:SpinnerListContainer height="266"
                            width="325"
                            x="10"
                            y="279">
        <s:SpinnerList change="From_changeHandler(event)"
                       enabled="true"
                       height="100%"
                       id="From"
                       labelField="data"
                       selectedIndex="1"
                       width="69">
            <s:ArrayList>
                <fx:Object data="Time">
                </fx:Object>
                <fx:Object data="KM">
                </fx:Object>
                <fx:Object data="Miles">
                </fx:Object>
            </s:ArrayList>
        </s:SpinnerList>
    </s:SpinnerListContainer>

    <s:TextInput id="somewhereToDisplaySelected"/>
</s:View>