MACROMEDIA FLASH 8-FLASH LITE 2.X ACTIONSCRIPT LANGUAGE Reference page 248

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

Advertisement

The Array class should not be used to create associative arrays, which are different data
structures that contain named elements instead of numbered elements. You should use the
Object class to create associative arrays (also called hashes). Although ActionScript permits you
to create associative arrays using the Array class, you can not use any of the Array class
methods or properties. At its core, an associative array is an instance of the Object class, and
each key-value pair is represented by a property and its value. Another reason to declare an
associative array as a type Object is that you can then use an object literal to populate your
associative array (but only at the time you declare it). The following example creates an
associative array using an object literal, accesses items using both the dot operator and the
array access operator, and then adds a new key-value pair by creating a new property:
var myAssocArray:Object = {fname:"John", lname:"Public"};
trace(myAssocArray.fname); // Output: John
trace(myAssocArray["lname"]); // Output: Public
myAssocArray.initial = "Q";
trace(myAssocArray.initial); // Output: Q
Availability: ActionScript 1.0; Flash Lite 2.0 - Became a native object in Flash Player 6,
which improved performance significantly.
Example
In the following example, my_array contains four months of the year:
var my_array:Array = new Array();
my_array[0] = "January";
my_array[1] = "February";
my_array[2] = "March";
my_array[3] = "April";
248
ActionScript classes

Advertisement

Table of Contents
loading

Table of Contents