1 Reply Latest reply on Jun 16, 2009 11:41 AM by Peter deHaan

    Getting a list's selected index

    Handycam Level 1

      I have a data list:

       

      <s:List id="stepList" width="100%" height="100%" contentBackgroundColor="0xffffff" selectionChanged="choiceMade(event)" />

       

      and I have the handler:

       

      private function choiceMade(e:IndexChangedEvent):void {

      trace(e.currentTarget.selectedIndex);

      }

       

      The problem is the trace statement always returns 2 numbers: the old index and the one it just changed to.  I only want to keep what is currently active (i.e. what the user chose).

        • 1. Re: Getting a list's selected index
          Peter deHaan Level 4

          Handycam,

           

          I can't reproduce that issue using Flex SDK 4.0.0.7836 and the following test case:

          <?xml version='1.0' encoding='UTF-8'?>
          <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/halo">
              <fx:Script>
                  <![CDATA[
                      import mx.events.IndexChangedEvent;
                      private function choiceMade(e:IndexChangedEvent):void {
                          debug.text = "ActionScript: " + e.currentTarget.selectedIndex.toString();
                      }
                  ]]>
              </fx:Script>
              <s:Panel width="400" height="300" initialize="sdkVer.text = mx_internal::VERSION;">
                  <s:layout>
                      <s:VerticalLayout />
                  </s:layout>
                  <s:List id="stepList" width="100%" height="100%" contentBackgroundColor="0xffffff" selectionChanged="choiceMade(event)">
                      <s:dataProvider>
                          <s:ArrayList>
                              <fx:String>The</fx:String>
                              <fx:String>Quick</fx:String>
                              <fx:String>Brown</fx:String>
                              <fx:String>Fox</fx:String>
                              <fx:String>Jumps</fx:String>
                              <fx:String>Over</fx:String>
                              <fx:String>The</fx:String>
                              <fx:String>Lazy</fx:String>
                              <fx:String>Doug</fx:String>
                          </s:ArrayList>
                      </s:dataProvider>
                  </s:List>
                  <s:SimpleText id="debug" />
                  <s:SimpleText text="Data binding: {stepList.selectedIndex}" />
                  <mx:HRule width="100%" />
                  <s:SimpleText id="sdkVer" />
              </s:Panel>
          </s:Application>
          

           

          Do you still see the issue if you try a newer build of the Flex SDK from http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4 ?

           

          Peter