Chapter 8: Working With Arrays - Adobe FLEX 2-PROGRAMMING ACTIONSCRIPT 3.0 Manual

Programming actionscript 3.0
Table of Contents

Advertisement

var myArray:Array = ["one", "two", "three"];
trace(myArray); // output: one,two,three
The Array class also contains properties and methods that allow you to modify indexed arrays.
These properties and methods apply almost exclusively to indexed arrays rather than
associative arrays.
Indexed arrays use an unsigned 32-bit integer for the index number. The maximum size of an
32
indexed array is 2
-1 or 4,294,967,295. An attempt to create an array that is larger than the
maximum size results in a run-time error.
An array element can hold a value of any data type. ActionScript 3.0 does not support the
concept of typed arrays, which means that you cannot specify that all the elements of an array
belong to a specific data type.
This section explains how to create and modify indexed arrays using the Array class, starting
with how to create an array. The methods that modify arrays are grouped into three categories
that cover how to insert elements, remove elements, and sort arrays. Methods in a final group
treat an existing array as read-only; these methods merely query arrays. Rather than modifying
an existing array, the query methods all return a new array. The section concludes with a
discussion about extending the Array class.
Creating arrays
The Array constructor function can be used in three ways. First, if you call the constructor
with no arguments, you get an empty array. You can use the
property of the Array
length
class to verify that the array has no elements. For example, the following code calls the Array
constructor with no arguments:
var names:Array = new Array();
trace(names.length); // output: 0
Second, if you use a number as the only parameter to the Array constructor, an array of that
length is created, with each element's value set to
. The argument must be an
undefined
unsigned integer between the values 0 and 4,294,967,295. For example, the following code
calls the Array constructor with a single numeric argument:
var names:Array = new Array(3);
trace(names.length); // output: 3
trace(names[0]); // output: undefined
trace(names[1]); // output: undefined
trace(names[2]); // output: undefined
228
Working with Arrays

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex

Table of Contents