User Guide

102 Chapter 2: ActionScript Language Reference
Array()
Availability
Flash Player 6.
Usage
Array() : Array
Array(numElements:Number) : Array
Array( [element0:Object [, element1 , element2,...elementN ] ]) : Array
Parameters
element
One or more elements to place in the array.
Returns
An array.
Description
Conversion function; creates a new, empty array or converts specified elements to an array. Using
this function is similar to creating an array with the Array constructor (see “Constructor for the
Array class” on page 104).
Example
Usage 1: The following example adds items to an array by using the arrays index and then by
using the Array classs
push method:
var myArray:Array = Array();
myArray.push(12);
trace(myArray); //traces 12
myArray[4] = 7;
trace(myArray); //traces 12,undefined,undefined,undefined,7
Usage 2: The following example creates an array of length 4 but with no elements defined:
var myArray:Array = Array(4);
trace(myArray.length); // traces 4
trace(myArray); // traces undefined,undefined,undefined,undefined
Usage 3: The following example creates an array with three defined elements:
var myArray:Array = Array(["firstElement", "secondElement", "thirdElement"]);
trace (myArray); // traces firstElement,secondElement,thirdElement
Note: Unlike the Array class constructor, the Array() function does not use the keyword new.
See also
Array class
CHAPTER 2
ActionScript Language Reference