Accessing Array Data

Accessing Array Data

Flash CS4 ActionScript 3.0 Tutorial


How To Organize Retrieve Data from Array Variable with Flash ActionScript



Arrays are used to organize large amounts of data. Arrays can be described as multi-dimensional variables that can hold several values. Once you have loaded your Array, you may want to retrieve specific values

Let's say you created an Array variable that stored three secret passwords, red, green and blue.

You placed red in slot [0], green in slot [1] and blue in slot [2]. In this exercise we will load the Array as described above, then recall the password in slot [1].

For more information on Arrays, see topics, Arrays, Loading an Array and Manipulating Array Contents.


Step One

Open a new Flash document and name the default layer Actions.

Step Two

Option double-click (PC - Alt double-click) frame one of the Actions layer.

Step Three

Copy/Paste the following code to the ActionScript panel.

var passWord:Array = new Array("Red", "Green", "Blue");


Step Four

Publish your movie by pressing Cmd/Return (PC - Ctrl/Enter). The value of the second password appears in the Output panel.

Dissecting the Code

The first line of the code at Step Three establishes a new variable named passWord. For the passWord variable, Red is loaded in slot [0], Green is in slot [1] and Blue is loaded in slot [2].

To see the contents of the Array, second value, we added a trace statement.