Flash Lite 2 |
|||
| Flash Lite 2.x ActionScript Language Reference > ActionScript classes > Array | |||
Object
|
+-Array
public dynamic class Array
extends Object
The Array class lets you access and manipulate indexed arrays. An indexed array is an object whose properties are identified by a number representing their position in the array. This number is referred to as the index. All indexed arrays are zero-based, which means that the first element in the array is [0], the second element is [1], and so on. To create an Array object, you use the constructor new Array(). To access the elements of an array, you use the array access ([]) operator.
You can store a wide variety of data types in an array element, including numbers, strings, objects, and even other arrays. You can create a multidimensional array by creating an indexed array and assigning to each of its elements a different indexed array. Such an array is considered multidimensional because it can be used to represent data in a table.
Array assignment is by reference rather than by value: when you assign one array variable to another array variable, both refer to the same array:
var oneArray:Array = new Array("a", "b", "c");
var twoArray:Array = oneArray; // Both array variables refer to the same array.
twoArray[0] = "z";
trace(oneArray); // Output: z,b,c.
The Array class should not be used to create associative arrays, which are different data structures that contain named elements instead of numbered elements. You should use the Object class to create associative arrays (also called hashes). Although ActionScript permits you to create associative arrays using the Array class, you can not use any of the Array class methods or properties. At its core, an associative array is an instance of the Object class, and each key-value pair is represented by a property and its value. Another reason to declare an associative array as a type Object is that you can then use an object literal to populate your associative array (but only at the time you declare it). The following example creates an associative array using an object literal, accesses items using both the dot operator and the array access operator, and then adds a new key-value pair by creating a new property:
var myAssocArray:Object = {fname:"John", lname:"Public"};
trace(myAssocArray.fname); // Output: John
trace(myAssocArray["lname"]); // Output: Public
myAssocArray.initial = "Q";
trace(myAssocArray.initial); // Output: Q
Availability: ActionScript 1.0; Flash Lite 2.0 - Became a native object in Flash Player 6, which improved performance significantly.
In the following example, my_array contains four months of the year:
var my_array:Array = new Array(); my_array[0] = "January"; my_array[1] = "February"; my_array[2] = "March"; my_array[3] = "April";
|
Modifiers |
Property |
Description |
|---|---|---|
|
|
Represents case-insensitive sorting. |
|
|
|
Represents a descending sort order. |
|
|
|
A non-negative integer specifying the number of elements in the array. |
|
|
|
Represents numeric sorting instead of string-based sorting. |
|
|
|
Represents the option to return an indexed array as a result of calling the |
|
|
|
Represents the unique sorting requirement. |
Properties inherited from class Object constructor (Object.constructor property), __proto__ (Object.__proto__ property), prototype (Object.prototype property), __resolve (Object.__resolve property)
|
Signature |
Description |
|---|---|
|
Lets you create an array. |
|
Modifiers |
Signature |
Description |
|---|---|---|
|
|
Concatenates the elements specified in the parameters with the elements in an array and creates a new array. |
|
|
|
Converts the elements in an array to strings, inserts the specified separator between the elements, concatenates them, and returns the resulting string. |
|
|
|
Removes the last element from an array and returns the value of that element. |
|
|
|
Adds one or more elements to the end of an array and returns the new length of the array. |
|
|
|
Reverses the array in place. |
|
|
|
Removes the first element from an array and returns that element. |
|
|
|
Returns a new array that consists of a range of elements from the original array, without modifying the original array. |
|
|
|
Sorts the elements in an array. |
|
|
|
Sorts the elements in an array according to one or more fields in the array. |
|
|
|
splice |
Adds elements to and removes elements from an array. |
|
|
Returns a string value representing the elements in the specified Array object. |
|
|
|
Adds one or more elements to the beginning of an array and returns the new length of the array. |
Methods inherited from class Object