Not yet rated

Problem

Flash Lite 1.1 does not support ActionScript 2.0, so the array() construct does not exist. This means arrays are not supported in Flash Lite 1.1 through a typical declaration.

Solution

Creating a "pseudo array" (or; "fake array" if you will) is one possible method to dealing with storing multiple variables/values in an array-like-structure in Flash Lite 1.1

Detailed explanation

Arrays are convenient method for storing ordered lists of multiple variables in a compact manner across many popular (mobile) programming languages. However, since Flash Lite 1.1 is based on legacy Flash Player 4 syntax, arrays are not supported in that particular version of the player (they are however, supported in Flash Lite 2.x and above). 

For example, if we had an array of three elements: red, green, and blue; this is how that data might be represented in ActionScript 2.0 which is found in Flash Lite 2.x and above, and is probably most familiar to what you might expect:

//-- Typical Flash Lite 2.x, 3.x array constructor syntax

var colors_arr:Array = new Array( "red", "green", "blue" );

for ( var i:Number = 0; i < 3; i++ ) {

 trace( colors_arr[ i ] );

}

However, when dealing with Flash Lite 1.1, it is possible to simulate an array, by creating what is otherwise known as a "pseudo array" in Flash Lite 1.1.

This is the equivalent ActionScript code written so it works in Flash Lite 1.1 (Flash 4 style syntax): 

 

//-- Flash Lite 1.1 "pseudo array" workaround

colors0_arr = "red";

colors1_arr = "green";

colors2_arr = "blue";

for ( i = 0; i < 3; i++ ) {

 trace( eval( "colors" add i add "_arr" ) );

}

 

Here we are assigning three unique variables which will contain our array elements (red, green, blue), and then utilizing the eval() statement to dynamically access each array position by forming the variable name using the add keyword to string together the correct indices. The effect is a pseudo array in Flash Lite 1.1.

You may utilize this technique quite often when creating complex applications, or casual games in Flash Lite 1.1.

This is one of a few techniques for dealing with arrays in Flash Lite 1.1 content (see method #2 in a different tip contained within this text).


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes