View comments | RSS feed

Array function

Array() : Array
Array(numElements:Number) : Array
Array(element0:Object, [element1, element2, ...elementN]) : Array

Creates a new array of length 0 or more, or an array populated by a list of specified elements, possibly of different data types.

Use Array() to create one of the following:

Using this function is similar to creating an array with the Array constructor (see "Constructor for the Array class").

You can pass a number (numElements) or a list of elements containing one or more different types (element0, element1, ... elementN).

Parameters that can accept more than one data type are listed in the signature as type Object.

Availability: ActionScript 1.0; Flash Player 6

Parameters

numElements:Number [optional] - A positive integer that specifies the number of elements in the array. You can specify either numElements or the list of elements, but not both.

elementN:Object [optional] - One or more parameters, element0, element1, ... , elementN, the values of which can be of any type. Parameters that can accept more than one data type are listed as type Object. You can specify either numElements or the list of elements, but not both.

Returns

Array - An array.

Example

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
Unlike the Array class constructor, the Array() function does not use the keyword new .

See also

Array


Version 8

Comments


No screen name said on Mar 9, 2006 at 7:52 AM :
Doesn't Array function should means casting in actionscript 2.0? Since the notation of Array( object ) signify this statement:

var anArray:Array = Array( object );

regardless the value of object?
No screen name said on Aug 24, 2006 at 10:03 PM :
I am working on Flash Professional 8. My flash file settings are
1) Flash Player 6.0
2) Action Script 1.0 version

I tried the following code for arrays given in live docs

var myArray:Array = Array();
myArray.push(12);
trace(myArray); //traces 12
myArray[4] = 7;
trace(myArray); //traces 12,undefined,undefined,undefined,7

I am getting undefined for both the trace statements. Even though it is given that array is supported by flash player 6.0 and action script 1.0.
Can someone help me?

Thanks
Shashank
juankpro said on Aug 1, 2007 at 7:31 AM :
The Array, Number and Boolean functions are just convertion functions on AS 2.0. Any other class is used as a casting.

Answering the previous question. You gen undefined because the (var myArray:Array = Array();) line is not supported in AS 1.0, because AS 1.0 does not support strict data typing, remove the :Array datatype:

var myArray = Array();

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001718.html