I am not sure why you have duplicate items. I am assuming these items come
from a database, you can use the query to leave out double records. In most
other cases, the double is in there for a reason, which means you do not
want to delete them. In that case you would like the .filterFunction
property. The filterFunction property is used to make sure an item is not
displayed while it is in the collection, this is used as follows:
*arrayCollection.filterFunction = removeDuplicate;
function removeDuplicate(item:Object):Boolean
{
/*
Do you magic here. More then one option exists. You could create
fingerprint of your object here and
store it in an object as a key, like this:
var ba:ByteArray = new ByteArray();
ba.writeObject(item);
var fingerprint:String = ba.toString();
if (checkObject.hasOwnProperty(fingerprint))
{
keepItem = false;
} else
{
checkObject[fingerprint] = true;
keepItem = true;
};
The above method only works if you data does not contain an ID.
Another option (which might be faster
in most cases, testing required) is to loop over the collection and
check if the items that contain the same
data are infact the same objects. In this case I would not use a for
loop, but a while(i--) loop since these
tend to be a bit faster and order does not matter in this case.
*/
};*
In order to apply the filter use the .refresh method of the array
collection.
Greetz Erik
On 5/9/08, Juan Pablo Califano [EMAIL PROTECTED] wrote:
If you're going to remove elements with a splice, you should loop backwards
(for var i:Number = array.length - 1;i = 0; i++), because when you loop
forward and take out one element, the relative position of the next items
will change.
Cheers
Juan Pablo Califano
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders