flex-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shervin Asgari <shervin.asg...@webstep.no>
Subject Specific sorting, then alphabetic
Date Wed, 27 Feb 2013 08:31:54 GMT

I am very very new to Flex.
I created this thread for sorting in Java

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;

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

Regards Shervin

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message