0 Replies Latest reply on Dec 27, 2010 12:08 PM by xinonnet

    A better example to demonstrate bugs in s:List

    xinonnet

      <?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/mx"

         creationComplete="changeToDp1()"

         minWidth="955" minHeight="600">

       

      <fx:Script>

      <![CDATA[

      import mx.collections.ArrayCollection;

       

      [Bindable]

      public var shared:String = "[Share]";

       

       

      private var dp1:ArrayCollection = new ArrayCollection( [ shared, "dp1" ] );

      private var dp2:ArrayCollection = new ArrayCollection( [ shared, "dp2" ] );

      private var dp3:ArrayCollection = new ArrayCollection( [ shared, "dp3" ] );

       

       

      public function changeToDp1():void {

      list.dataProvider = dp1;

      list.selectedItem = shared;

      }

      public function changeToDp2():void {

      list.dataProvider = dp2;

      list.selectedItem = shared;

      }

      public function changeToDp3():void {

      list.dataProvider = dp3;

      list.selectedItem = shared;

      }

      ]]>

      </fx:Script>

       

      <s:layout>

           <s:VerticalLayout />

      </s:layout>

       

      <s:Button label="dp1" click="changeToDp1()" />

      <s:Button label="dp2" click="changeToDp2()" />

      <s:Button label="dp3" click="changeToDp3()" />

       

      <s:List id="list" />

      <s:HGroup>

           <s:Label text="list.selectedItem" />

           <s:Label text="{list.selectedItem}" />

      </s:HGroup>

      <s:HGroup>

           <s:Label text="list.selectedIndex" />

           <s:Label text="{list.selectedIndex}" />

      </s:HGroup>

      </s:Application>

       

       

      In this example, three dataProviders share a *single instance* of a String.  Since selectedItem is always set to this shared String, no matter which dataProvider is chosen, list.selectedIndex should never be -1.  In fact, "shared" is the first element in every dataProvider, therefore, selectedIndex should always be 0.

       

      If you keep clicking the dp Button's, you will see that selectedIndex eventually goes to -1.

       

      In fact, if you click on any one of the dp Button's multiple times, you will the labels change between { [Share], 0 } and { "", -1 }