Accessibility

ActionScript cookbook beta

Create and loop through an Array

Problem Summary

You need to create an Array and loop through its values.

Solution Summary

Use a for loop to loop through the Array.

Explanation

ActionScript 2

var a:Array = ["a", "b", "c", "d"];

var len:Number = a.length;

for(var i:Number = 0; i < len; i++)
{
   trace(a[i]);
}

ActionScript 3

var a:Array = ["a", "b", "c", "d"];

var len:Number = a.length;

for(var i:Number = 0; i < len; i++)
{
   trace(a[i]);
}

Note: You can also use the Array constructor and push method to populate an Array like so:

var a:Array = new Array();
a.push("a");
a.push("b");
a.push("c");
a.push("d");