2012-02-21 41 views
0

我正在学习Adobe Air,并希望获得我创建的微调列表中的当前选定项目,但是每次使用selectedItem无论我选择什么选项,我都会一直得到相同的值。我试图让该剧本的应用程序,和本我SpinnerList代码:如何使用微调列表访问Adobe Air中的选定项目?

<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

使用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>