Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-20-2009, 10:47 PM   #1
barry
Member
 
Join Date: Jul 2002
Posts: 84
Default Issue with TileList, ArrayCollection and sort

Hi,

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?

Cheers.
barry is offline   Reply With Quote
Old 01-21-2009, 12:57 AM   #2
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

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.
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 01-23-2009, 12:04 PM   #3
barry
Member
 
Join Date: Jul 2002
Posts: 84
Default

Hi WVXVW,

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.

Cheers.
barry is offline   Reply With Quote
Old 01-23-2009, 04:30 PM   #4
barry
Member
 
Join Date: Jul 2002
Posts: 84
Default

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().

ActionScript Code:
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.refresh();                         _images.sort = null;                         _images.source = _images.toArray();     } }

if you just call

ActionScript Code:
_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,

ActionScript Code:
_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.
barry is offline   Reply With Quote
Old 01-23-2009, 05:39 PM   #5
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

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:
http://bugs.adobe.com/jira/browse/SDK-18390
http://bugs.adobe.com/jira/browse/SDK-8741
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid column position changes after doing sort bidur Flex 2, 3 & 4 0 01-06-2009 06:34 AM
ArrayCollection removeAll problem doorman Flex 2, 3 & 4 5 10-08-2008 01:07 PM
Best practice: two DataGrids\one ArrayCollection hillel369 Flex 2, 3 & 4 4 09-24-2008 07:46 PM
Array collection sort kminev Flex 2, 3 & 4 4 07-07-2008 01:59 PM


All times are GMT. The time now is 12:33 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.