Re: [Flashcoders] Data merging problem

2008-05-15 Thread EECOLOR
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


Re: [Flashcoders] Data merging problem

2008-05-09 Thread Eduardo Omine
Remove the entry from the array?
workData.splice(1, 1);

-- 
Eduardo Omine
http://blog.omine.net/
http://www.omine.net/
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Data merging problem

2008-05-09 Thread Jason Van Pelt
This is untested so it may need a bit of tweaking, but you could do
something like this:

// for each item in the array
for(var i = 0; i  workData.length; i++){

  // compare to all other array elements
  for(var j = 0; j  workData.length; j++){

// do your comparison(s), making sure not to compare to itself
if(workData[i].pm == workData[j].pm  i != j){

  // overwrite the propeties of the first element with the
properties of the second
  for(var props in workData[i]){
workData[i][props] = workData[j][props];
  }

  workData.splice(1,j);
}
  }
}


Things to consider--
Will all elements in your array have the same properties?
Do you need more logic involved in figuring out which properties should be
the ones to keep?


Jason Van Pelt
Interactive Developer
504.210.1232 (p) / 504.581.2731 (f)
Peter A. Mayer Advertising, Inc.
www.peteramayer.com
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders