ACTIONSCRIPT 3 TUTORIALS

Arrays, Some Array Methods and Properties, and Looping through an Array

//Arrays
//Arrays are used to create ordered lists of information
//Each item in an array is called an array "element", and it's position within the array is called its "index"

//Create a new array called "diveSites" and populate it with a list
var diveSites:Array = ["Bonaire", "Cozumel", "Roatan", "Belize"];

//Methods and properties of arrays include push, pop, shift, unshift and splice
diveSites.push("Saba");
//diveSites.pop();
//diveSites.shift();
//diveSites.unshift("Saba");
//diveSites.splice(3,0,"Hawaii","Palua");

trace (diveSites.length);
trace(diveSites);

//var myNumbers:Array = new Array(1, 3, 5, 7, 9);
//trace (myNumbers[2]);

//Create a new array, then populate it based on index position
var myList:Array = new Array();
myList[0] = "Monday";
myList[1] = "Tuesday";
myList[2] = "Wednesday";
myList[3] = "Thursday";
myList[4] = "Friday";

//trace(myList[2]);

//Looping through an array

for (var i:int = 0; i < myList.length; i++) {
trace(myList[i]);
}

//Looping through an array with the for in loop; with "for in" the variable will take on the index position of the elment in the array

for (var a in myList) {
//trace(a);
trace(myList[a]);
}

//Looping through an array with the for each in loop; with "for each in" the variable will take on the value of each element in the array

for each (var b:String in myList) {
trace(b);
}