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

Flash ActionScript Tutorial: Assign Values to Array (1)

This Flash ActionScript tutorial shows how to create new Arrays and how to assign values to Arrays.

Please update flash player to view this Flash ActionScript tutorial!

Flash Tutorial Content:

To use the Array, values must be assigned or added to the Array. There are some methods to assign values to an Array. This Flash ActionScript tutorial shows a common method to assign value to an 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
//We are going to make some ice cubes with different taste
//Five different juices 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.
var trayArray:Array = new Array("papaya juice", "orange juice", "apple juice", "milk", "coke");


//The value of individual element in the Array can be retrieved
//with reference to the element index
//Each element has an element index
//The element index of the first element is 0
//The element index of the second element is 1
item1_txt.text = trayArray[0];
item2_txt.text = trayArray[1];
item3_txt.text = trayArray[2];
item4_txt.text = trayArray[3];
item5_txt.text = trayArray[4];


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

Download Flash Source File:

Flash Source File array-2.fla


This Flash ActionScript tutorial shows how to create and assign values to Array. As you noticed that the values are assigned to the Array when the Array was created. Many flash developer don't like this. They would like to create an empty Array first then assign values to the Array later on. The next Flash ActionScript tutorial will show this method.