Flash AS3 Helps: For Loop Statement in Flash AS3 ( ActionScript3)

I used the For loop statement all the time in ActionScript 2.0 for all sorts of things: traversing XML nodes, creation of arrays; assign values to symbol instances, etc. The For statement is very valuable in my opinion and should be in every ActionScripter’s toolbox.

In AS3, the For statement’s syntax is just a little different but still works the same.  Here is a quick sample:

var myArray:Array = new Array();
for (var z:Number = 0; z < 11; z++) {
myArray[z] = (z + 1) * 2;
}
trace(myArray);
//this tracet: 2,4,6,8,10,12,14,16,18,20,22

3 Responses to “Flash AS3 Helps: For Loop Statement in Flash AS3 ( ActionScript3)”

  1. D-mode Blog » Flash AC3 ( actionscript 3): XML video player, plays FLV files from XML Says:

    [...] 3 ) example that combines a couple things that I’ve posted in the past, including the for loop and xml loading. So we use those methods in this FLV Video playlist sample. Since the xml file is [...]

  2. D-mode Blog » Flash Helps: AS3 (actionScript 3) Podcast Player Says:

    [...] 3 Podcast player. This little sample uses similar Flash AS3 methods in past posts like the for loop, xml loading, and the Flash AS3 Video [...]

  3. D-mode Blog » Flash Helps: Flash CS3 List Component in AS3 (actionScript 3 ) Says:

    [...] lets build a functioning app using the Flash list component, arrays, for loop, and [...]