I wouldn't give a Sort and a compareFunction - what's the point ? Just have one or the other.

Either way, this wont empty your ArrayCollection. If you dump it out before and after

var grunner:ArrayCollection

along with where ever it came from, are your *sure* it isn't being populated by an empty array, null object, failed cast etc. ?

Failing that, make a standalone example we can all build.

Tom

On 27/02/2013 08:31, Shervin Asgari wrote:
Hi.

I am very very new to Flex.
I created this thread for sorting in Java
http://stackoverflow.com/q/15091732/37298

However, I am now trying to do the same thing in ActionScript.

I have a Bindable ArrayCollection with Objects that looks like this

Code.code : F
Code.label: Foo
Code.description: The Foo description

Then I want to sort exactly as specified in the stackoverflow site.
I have around 10 of them which I need in a particular order. I have them
defined in an array.

Based on the stackoverflow question and some googling, I have come up with
the following:

private function myCompare(a:Object, b:Object, fields:Array = null):int {
             if (mostUsed.contains(a.code) && mostUsed.contains(b.code)) {
                 return fields.getItemIndex(a) - fields.getItemIndex(b);
             }

             if (mostUsed.contains(a.code)) {
                 return -1;
             }

             if (mostUsed.contains(b.code)) {
                 return 1;
             }

             var s:Sort = new Sort();
             s.fields = fields;
             var f:Function = s.compareFunction;
             return f.call(null,a,b,fields);
         }

private var mostUsed:ArrayCollection = new ArrayCollection(["F", "A", "B",
"FTR", "HIS", "KEB", "LEG", "MED", "MER", "PEN", "PEO", "PER", "PIN",
"PUR", "REF"]);

var grunner:ArrayCollection = //getting collection
grunner.sort.fields = [new SortField("code")];
grunner.sort.compareFunction = myCompare;
grunner.refresh();

But it doesnt work. Any clues?
My collection returns empty.

Regards Shervin


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

Reply via email to