Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8897509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:21:49+00:00 2026-06-15T00:21:49+00:00

I’ve got an ArrayCollection that serves as a dataProvider for a list. The collection

  • 0

I’ve got an ArrayCollection that serves as a dataProvider for a list.

The collection stores objects of type MyObject:

public class MyObject {
    public var myMap:Dictionary;
}

myMapstores key-value pairs, the key being an integer, the values are Strings.

So far for the constraints. What I want to do now is to sort the collection based on fields of the map.

Using a the ArrayCollection‘s sort function with my own compareFunction does work. This is how I’ve implemented it:

    var key:int = 15;
    var sort:Sort = new Sort();
    sort.compareFunction = fidSort;
    myCollection.sort = sort;
    myCollection.refresh();

    private function fidSort(a:Object, b:Object, fields:Array = null):int {
        if(a.myMap[key].fieldValue == b.myMap[key].fieldValue) {
            return 0;
        } else if(a.myMap[key].fieldValue > b.myMap[key].fieldValue) {
            return 1;
        } else{
            return -1;
        }
    }

As I said, that does work for the sake of sorting. However, naturally the sort (being a property of the collection) remains on the collection unless specifically removed from it, which means that every time a value in the map of MyObject changes, it will get sorted according the comparefunction.

What I need is to apply the sort exactly once, what happens afterwards with the map values shouldn’t change the collections sorting.

I’ve tried things like disabling autoupdate on the colleciton (naturally that won’t work as the collection doesn’t get any updates any more (well it does, but they are cached only)).
After that I’ve read this post about sorting the underlying array.
However, that doesn’t seem to work with the map, as I do get a compile error saying that the myMap[key].fieldValue couldn’t be found on MyObject.

So yes, I’m kinda lost in space here. If someone has a clue how to achieve this, very basic task really, please let me know.

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:21:50+00:00Added an answer on June 15, 2026 at 12:21 am

    Got it, and for the sakes of completeness, I’d like to answer this question myself.

    As said before, using myCollection.toArray().sort(fidSort) didn’t work completely. The array made in this step has indeed been sorted, the collection, however, didn’t get the sort, even though refresh() has been called.

    To fix this, instead of creating a new array from the collection, we need to directly use the collection’s source (which is an array of course) and sort that array;

      collection.source.sort(fidSort);
      collection.refresh();
    

    Since we are still only sorting the array and not applying the Sort to the collection itself, the collection is sorted only once, regardless of the updates to it’s data.

    Edit: Just for kicks, restoring the original item positions isn’t possible out of the box when sorting the collection‘s underlying array like it can be done when applying a sort on an ArrayCollection directly and setting it to null to restore the positions.
    Simple solution is to cache the array item indices beforehand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I know there's a lot of other questions out there that deal with this
i got an object with contents of html markup in it, for example: string
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.