[] Array Access Operator - MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference

Flash lite 2.x actionscript language reference
Hide thumbs Also See for FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE:
Table of Contents

Advertisement

Example
Usage 1: This example uses the
operator with a string expression and sends "My name is
+=
Gilbert" to the Output panel.
var x1:String = "My name is ";
x1 += "Gilbert";
trace(x1); // output: My name is Gilbert
Usage 2: The following example shows a numeric use of the addition assignment (
)
+=
operator:
var x:Number = 5;
var y:Number = 10;
x += y;
trace(x); // output: 15
See also
+ addition operator

[] array access operator

myArray = [ a0, a1,...aN ]
myArray[ i ] = value
myObject [ propertyName ]
Initializes a new array or multidimensional array with the specified elements (
, and so on),
a0
or accesses elements in an array. The array access operator lets you dynamically set and retrieve
instance, variable, and object names. It also lets you access object properties.
Usage 1: An array is an object whose properties are called elements, which are each identified
by a number called an index. When you create an array, you surround the elements with the
array access ([]) operator (or brackets). An array can contain elements of various types. For
example, the following array, called
, has three elements; the first is a number and
employee
the second two are strings (inside quotation marks):
var employee:Array = [15, "Barbara", "Jay"];
You can nest brackets to simulate multidimensional arrays. You can nest arrays up to 256
levels deep. The following code creates an array called
with three elements; each
ticTacToe
element is also an array with three elements:
var ticTacToe:Array = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; // Select Debug >
List Variables in test mode
// to see a list of the array elements.
Usage 2: Surround the index of each element with brackets ([]) to access it directly; you can
add a new element to an array, or you can change or retrieve the value of an existing element.
The first index in an array is always 0, as shown in the following example:
120
ActionScript language elements

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE and is the answer not in the manual?

Table of Contents