266
ActionScript classes
Parameters
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.
Returns
Array
- An array containing the elements that were removed from the original array.
Example
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
Summary of Contents for FLASHLITE2 ACTIONSCRIPT-LANGUAGE
Page 1: ...Flash Lite 2 x ActionScript Language Reference...
Page 22: ...22 Contents...
Page 244: ...244 ActionScript language elements...
Page 760: ...760 ActionScript classes...