The Array.splice method, in AS1 at least, is very slow. For that reason, In situations like this where you would make repeated calls to it to remove one item I prefer to:
- create a new Array
- iterate the original array with a for loop
- push the items I want to keep into the new array
- dispose the old one when done.


On Dec 22, 2006, at 12:09 AM, Arindam Dhar wrote:

Try this,

  var myArray1:Array = new Array();
myArray1.push( new Array("A:", -1) );
myArray1.push( new Array("B:", -1) );
myArray1.push( new Array("C:",  0) );
myArray1.push( new Array("D:",  0) );
myArray1.push( new Array("E:", -1) );
myArray1.push( new Array("F:",  1) );
myArray1.push( new Array("G:",  0) );
myArray1.push( new Array("H:", -1) );
trace( myArray1);

  // the function with recursion

  function removeElements(arr, level) {

 for (var i = 0; i<arr.length; i++)
 {
  var tempArr = arr[i];

   if(Number(tempArr[1] ) < Number(level))
   {
    arr.splice(i, 1);
    arguments.callee(arr, level);
   }

 }
}
removeElements(myArray1, 0);
trace( myArray1);

  ----  Arindam

Mike Cobb <[EMAIL PROTECTED]> wrote:
  -

Hi everyone,

I'm having a braindead moment today, which I was hoping someone could
help me with.

I have the following array...

//Create array with 5 elements
var myArray1:Array = new Array();
myArray1.push( new Array("A:", -1) );
myArray1.push( new Array("B:", -1) );
myArray1.push( new Array("C:", 0) );
myArray1.push( new Array("D:", 0) );
myArray1.push( new Array("E:", -1) );
myArray1.push( new Array("F:", 1) );
myArray1.push( new Array("G:", 0) );
myArray1.push( new Array("H:", -1) );
//name, score

...and I'm trying to remove all the elements in myArray1 with a score of
less than 0 without sorting/reordering the array at all.

I was trying to use a 'for loop', but obviously as the elements are
removed, the length of the array changes & causes the wrong elements to
be deleted.

Can anyone help?

Thanks,


--
-------------------------------------
Mike Cobb
Creative Director
HMC Interactive
-------------------------------------
Tel: + 44 (0)845 20 11 462
Mob: + 44 (0)785 52 54 743
Web: http://www.hmcinteractive.co.uk
-------------------------------------
Grosvenor House, Belgrave Lane,
Plymouth, PL4 7DA, UK.
-------------------------------------

I've got a new e-mail address: [EMAIL PROTECTED]
Please update your address book. Thanks.

_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


Send instant messages to your online friends http:// asia.messenger.yahoo.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to