View Full Version : Issue with TileList, ArrayCollection and sort

01-20-2009, 10:47 PM

i've been having some issues when using the sort() method of an ArrayCollection that acts as a dataProvider for a TileList.

The ArrayCollection contains a list of objects that i want to be able to sort by different properties and display the changes of order within the TileList. Dragging is also enabled on the TileList and everything works as expected as long as the sort method of the ArrayCollection isn't called. I can drag and drop objects around within the TileList to change the order within the ArrayCollection and if i trace the ArrayCollection and ArrayCollection.source, they appear to be the same list/Array of objects.

However, once ArrayCollection.sort has been called, the source array and the ArrayCollection start to differ and no longer mirror each other? The Array that's the source property of the ArrayCollection reflects any changes that have been made to the ArrayCollection from dragging and dropping objects within the TileList, but the ArrayCollection stays the same as when the sort method was called. The TileList appears to reflect the ArrayCollection as opposed to its source Array, so nothing changes within the TileList when Objects are dragged and dropped around?

I call the ArrayCollection.refresh() method once sort has been called on the ArrayCollection and this also works fine, changing the order of the Objects within the TileList to reflect this change. But once it's been called, no more changes can be made (visually), through dragging and dropping. Also the CollectionEvent.COLLECTION_CHANGE is still being fired when ever any changes (through sort or drag and drop) are made, so this doesn't appear to be the issue.

From what i can see through attempting to debug this problem, once the sort method of the ArrayCollection has been called, the source Array and the ArrayCollection appear to become seperate Arrays/lists? Changes still get made to the source property of the ArrayCollection (it's raw Array), but the List of the ArrayCollection stops changing when dragging and dropping.

I hope all this makes sense, apologises that it's a bit long winded, am i missing something really obvious?


01-21-2009, 12:57 AM
Just a guess: what if you pass null for the Sort object when changing the order manually? Because it seems that sorting may be the way of representing data without making changes to the actual order. I.e. once you assign a new Sort object to ArrayCollection.sort it will lock it up until you sort it differently / nullify this property.

01-23-2009, 12:04 PM

thanks for your reply, apologises for the delay in mine, i've been away for the last few days.

I gave your suggestion a try, but unfortunately it throws an error within the getFilteredItemIndex() method of the ListItemCollection. This is the error that gets thrown.

TypeError: Error #1006: value is not a function.

I think you might be right though, about the fact that after sort has been called, the ArrayCollection appears to get locked, so that manual changes cannot be applied. Having looked at the docs, the only thing that i could find that appears to relate to this (on the ArrayCollection) are the disableAutoUpdate() and enableAutoUpdate() methods, but i tried calling enableAutoUpdate() after sort has been called and it doesn't appear to make any difference?

Like i said in my first post, what appears to happen once sort has been called, is that the source Array of the ArrayCollection and the ArrayCollection itself (or it's List?) then start to differ in their ordering as if they've become unrelated?

I'm going to carry on looking into this from the point that the error is thrown and will let you know my findings.


01-23-2009, 04:30 PM
This is not so much a solution, but a workaround. I can't seem to find a way of 'unlocking' the ArrayCollection once a sort has been set on it, at which point any manual sorting using drag and drop fails to work.

So instead i call sort, refresh, set sort to null and then set the source of the ArrayCollection as it's own List as an Array, by calling ArrayCollection.toArray().

public function set mode( md:String ):void
if( _mode != md )
_mode = md;

var srt : Sort = new Sort();
srt.fields = [ new SortField( _mode, false, false, true ) ];

_images.sort = srt;


_images.sort = null;

_images.source = _images.toArray();

if you just call

_images.sort = null;

then try and drag and drop, the Error is thrown. But if you don't call it before setting the source of the Array as it's own list as Array, the source and the ArrayCollection match each other, but the ArrayCollection is still locked? So i have to do this,

_images.sort = null;

_images.source = _images.toArray();

There must be a way to unlock the ArrayCollection once sort has been set, but i don't seem to be able to work out what it is? At least this workaround will stop my head from exlpoding.

01-23-2009, 05:39 PM
Maybe you can post this as a feature request at bugs.adobe.com ? It seams to me this is rather a lack of feature (i.e. "unsort" the collection would be the feature). I also didn't find a way to "unlock" the collection after it's being sorted.
See also this 2 bugreports: