Flash AS3 Tutorials Center | Interesting Flash Animation Tutorials | Valuing Flash Animation Tutorials | Flash ActionScript and Animation Home

AS3 Beginner Tutorials | AS3 Basic Lessons | AS3 Valuing Courses | AS3 Components Tutorials | AS3 and PHP Interaction Tutorials
AS3 Practical Tutorials | AS3 Animation Techniques | AS3 Transition Effects Tutorials | AS3 Download Upload Files | AS3 Particle Systems
Communication Between Flash Movies with AS3 | AS3 and JavaScript interaction | AS3 Matrix Transformation | AS3 Physics Simulation Tutorials

Use For Loop to Retrieve Values from Array with Flash ActionScript 3

This Flash ActionScript tutorial shows how to access or retrieve values from Arrays with a For Loop statement.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

This Flash ActionScript tutorial uses a more efficient way to retrieve values of Array. We use a For Loop statement to retrieve values from Array.

The Flash Movie of this tutorial is shown as above.

Flash ActionScript Codes:

//Create an empty Array with the name trayArray
//You may imagine an Array like a DIY ice cube tray
//You don't need to decide the size at this moment
//You can assembly any number of ice cavity for your ice cube tray later
var trayArray:Array = new Array();

 

//We are going to make some ice cubes with different tastes
//Five different juices (values) are put into the Array
//Therefore the size of this Array is now 5
//Since this is a DIY ice cub tray, the size can be changed anytime.
trayArray = ["papaya juice", "orange juice", "apple juice", "milk", "coke"];

 

//The individual elements in the Array can be retrieved
//with reference to the element index
//The element index of the first element is 0
//The element index of the second element is 1
//etc...
//Let's use a for loop to do it. This is much simple.

var i:int;

for (i = 0; i < trayArray.length; i++) {

this["item" + (i + 1) + "_txt"].text = trayArray[i];

}

 

//Check the size of testArray
output_txt.text = "The size of trayArray are: " + trayArray.length;

Download Flash Source File:

Flash Source File array-4.fla

Remarks:

This Flash ActionScript tutorial also shows how to create and assign values to Array with a For Loop statement. We always require to know the last element or last value of an Array. The next ActionScript tutorial will show you how to access the last value of an Array.