Yeah, I second this suggestion. IViewCursor is your friend :) And I know I haven't added much to the discussion -- but I want to contribute, not just leech off everyone!
You guys are too quick to reply! :) On Tue, Nov 25, 2008 at 16:15, gabriel montagné <[EMAIL PROTECTED]>wrote: > On Mon, Nov 24, 2008 at 3:45 AM, bjorn <[EMAIL > PROTECTED]<itrashmail%40gmail.com>> > wrote: > > No one knows the answer to my initial question about why there is a > problem > > implementing removeItemAt()/addItemAt() on a sorted AC? > > Well, the cool thing about using those mx.collections.* classes, as opposed > to, for example, just using Arrays (besides binding, that is) is using a > cursor view of them so you don't really have to go counting with your > fingers > where a particular item is. > > If you have a sorted collection (of Point objects, lets say), you can > create a > cursor and use that to find, remove, etc. whatever it is that you're > looking > for. > > You can quickly do stuff like: > > // sort the items first by x, in descending order, then by y ascending > // (without cumbersome Array sort functions). > > var customSort:Sort = new Sort(); > customSort.fields = [ > new SortField("x", false, true), > new SortField("y") > ]; > collection.sort = customSort; > collection.refresh(); > > // later on, you need to find the first point, according to this order, > which > // has and x of 160 and and y of 130. Instead of looping through the set, > // you can use a cursor like this: > > var cursor:IViewCursor = collection.createCursor(); > var itemFound:Boolean = cursor.findFirst({x:160, y:130}) > > // now your cursor is pointing to the item you're looking for (you can > check > // on it by looking at the 'current' property), if it has found it. Without > // having to worry on which index it was, you can just then say: > > if (itemFound) > cursor.remove(); > > This is just a simple example of the sort of things that you should be > using > collections for. I'd suggest a quick glance over the IViewCursor docs to > see > how cool that approach is. Remember that collections (like ArrayCollection, > for example) are just particular views of rawer data sets; Their aim is > just > to make your life simpler in the end. > > HTH, > > -- > gabriel montagné láscaris comneno > http://rojored.com > t/506.8367.6794 > >