4 Replies Latest reply on Jul 3, 2012 8:09 AM by sadensmol

    List dataprovider refresh

    sadensmol Level 1

      Hello. I faced an issue on  AIR3.3. Is it bug? Please help me and advise.


      Very simple application for test




                                    import mx.collections.ArrayCollection;

                                    import mx.events.FlexEvent;


                                    import spark.collections.Sort;


                                    private var testCollection:ArrayCollection = new ArrayCollection();


                                    protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void {





                                                        var sort:Sort = new Sort();

                                                        sort.compareFunction = compareFunctionSort;

                                                        testCollection.sort = sort;





                                    private function compareFunctionSort (obj1:Object, obj2:Object,fields:Array = null) :int {

                                              return 0;



                                    protected function button1_clickHandler(event:MouseEvent):void {











                <s:List dataProvider="{testCollection}" itemRenderer="TestItemRenderer">


                                    <s:TileLayout id="usersListLayout" horizontalGap="5" verticalGap="5" horizontalAlign="left" verticalAlign="top" />



                <s:Button label="1" click="button1_clickHandler(event)"/>



      Here is an item renderer:

      <s:BorderContainer >




                          <s:Label text="{data}"/>

                          <s:Label text="{DebugUtils.getObjectMemoryHash(videoC)}"/>

        <mx:UIComponent id="videoC"/>



      After clicking on Button collection going to refresh. But always 0 returns from sort function!!!

      And what i see ( please check images )



      Screen Shot 2012-07-03 at 3.10.29 PM.png

      After click:

      Screen Shot 2012-07-03 at 3.10.40 PM.png



        • 1. Re: List dataprovider refresh
          tinylion_uk Level 2

          Your sort function isn’t doing anything.




          You aren’t actually doing a compare in there




          You need to compare the inputs and return a value dependant on the code in the method. You are telling it to do nothing.




          You need to follow the following rules


          Return value


          -1, if a should appear before b in the sorted sequence


          0, if a equals b


          1, if a should appear after b in the sorted sequence

          • 2. Re: List dataprovider refresh
            tinylion_uk Level 2

            And before writing WTF, try writing ‘google’


            Just do a search for arrayCollection compareFunction


            Lots of examples of how the compareFunction works.

            • 3. Re: List dataprovider refresh
              sadensmol Level 1

              Thank you for quick answer.


              Sorry for that hasty expression but there is not clearly behaivor.


              If i invoke collection.refresh() and no sort is needed for my collection it returns 0 in any combinations of items. So i get the same result incorrect visualisation of list.

              Going to ask google about arrayCollection compareFunction...

              • 4. Re: List dataprovider refresh
                sadensmol Level 1

                So Ive rewritten my sort function in according with first result from google



                                              private function compareFunctionSort (a:Object, b:Object,fields:Array = null) :int {

                                                        var cmpArray:Array = ["111", "222", "333"];

                                                        var aValue:Number = cmpArray.indexOf(a);

                                                        var bValue:Number = cmpArray.indexOf(b);

                                                        if(aValue == bValue)

                                                                  return 0;

                                                        if(aValue > bValue)

                                                                  return 1;

                                                        return -1;



                but got the same result. Visualization works incorrectly!!!


                Please have a look at the attached video