AS3 Arrays: Access elements in a string array

//String array

Example

var aString:Array = new Array ("Name", "Address", "State", "Zip", "Phone");
trace(aString);
//returns the contents of the array
trace(aString[1]);
//trace the position of an object in an array. Index position must be in brackets. This trace would return "address".
trace(aString.length);
//returns the length of the array. This trace would return "5"

AS3 Arrays: Array breakdown

var testArray:Array=new Array("name","address","state","zip","country");
//Naming the array variable

var testArray:Array=new Array("name","address","state","zip","country");
//Datatyping the variable as an Array

var testArray:Array=new Array("name","address","state","zip","country");
//Setting up a new array

var testArray:Array=new Array("name","address","state","zip","country");
//contents of the array. Each item is assigned a numerical index starting with 0. The example above would be (0,1,2,3,4).

Loops: Create a "for loop" in AS3

Create a button movieclip on your stage.
Give it an instance name of bStart.

Create an input text box on your stage.
Give it an instance name of itSteps.

Create a dynamic text box on your stage.
Give it an instance name of tMessages.

Actionscript:

bStart.addEventListener(MouseEvent.CLICK, fLoop);

itSteps.restrict = "0-9";
itSteps.maxChars = 3;

function fLoop(event:MouseEvent):void {
tMessages.text="";
var vString:String = itSteps.text;
var vExample:Number = Number(vString);
for (var i:Number=0; i < vExample; i++) { tMessages.appendText([i]+", "); } }

Example:

Get Adobe Flash player