views:

38

answers:

1

I have an array Items which has 10 elements. I need to remove the 5th element (index=4) the new array should have 9 elements and all elements after the 5th element will be shifted forward

what command(s) should i use?

A: 

Splice

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#splice%28%29

var vegetables:Array = new Array("spinach",
             "green pepper",
             "cilantro",
             "onion",
             "avocado");

var spliced:Array = vegetables.splice(2, 2);
trace(vegetables); // spinach,green pepper,avocado
trace(spliced);    // cilantro,onion

vegetables.splice(1, 0, spliced);
trace(vegetables); // spinach,cilantro,onion,green pepper,avocado
Leo