Flash CS3 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > Array > splice (Array.splice method) | |||
Adds elements to and removes elements from an array. This method modifies the array without making a copy.
Availability: ActionScript 1.0; Flash Player 5
startIndex:Number - An integer that specifies the index of the element in the array where the insertion or deletion begins. You can specify a negative integer to specify a position relative to the end of the array (for example, -1 is the last element of the array).
deleteCount:Number [optional] - An integer that specifies the number of elements to be deleted. This number includes the element specified in the startIndex parameter. If no value is specified for the deleteCount parameter, the method deletes all of the values from the startIndex element to the last element in the array. If the value is 0, no elements are deleted.
value:Object [optional] - Specifies the values to insert into the array at the insertion point specified in the startIndex parameter.
Array - An array containing the elements that were removed from the original array.
The following example creates an array and splices it by using element index 1 for the startIndex parameter. This removes all elements from the array starting with the second element, leaving only the element at index 0 in the original array:
var myPets_array:Array = new Array("cat", "dog", "bird", "fish");
trace( myPets_array.splice(1) ); // Displays dog,bird,fish.
trace( myPets_array ); // cat
The following example creates an array and splices it by using element index 1 for the startIndex parameter and the number 2 for the deleteCount parameter. This removes two elements from the array, starting with the second element, leaving the first and last elements in the original array:
var myFlowers_array:Array = new Array("roses", "tulips", "lilies", "orchids");
trace( myFlowers_array.splice(1,2 ) ); // Displays tulips,lilies.
trace( myFlowers_array ); // roses,orchids
The following example creates an array and splices it by using element index 1 for the startIndex parameter, the number 0 for the deleteCount parameter, and the string chair for the value parameter. This does not remove anything from the original array, and adds the string chair at index 1:
var myFurniture_array:Array = new Array("couch", "bed", "desk", "lamp");
trace( myFurniture_array.splice(1,0, "chair" ) ); // Displays empty array.
trace( myFurniture_array ); // displays couch,chair,bed,desk,lamp
Flash CS3
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00001368.html