Sunday, August 19, 2012

Flash CS3 Tutorial - Arrays


An array is essentially a container for the participation data, similar to the way waiting for data variable. The difference is that an array may contain multiple pieces of data. The position of each piece of data is defined as the index and will always fall in a specific sequence. These indices are numbers in sequence starting at zero. Since Flash numbers each piece of data within the array is easy for the programmer to access a specific piece of data at any time. In ActionScript you are not forced to contain a type of data in an array. This means that an array can contain any number of index 0, a name index 1, and a movie clip in index 2. Creating an array is quite simple, requiring only a two step process. The first is to declare the array, the second is to populate the array with the data.

Flash Array

Animation with matrices

To create an array to select the first keyframe on the actions layer in the timeline. Copy the sample code. This code is pretty simple. You are creating a variable called colorsArray, data typed as an array and setting it equal to a new array that is to create the array. To add data to the master copy and paste the code in the next example. With this code you are simply calling the name of the array, then the braces indicates the flash as an index of the array to use. Finally, it is telling flash to put something in a specified index.

var colorsArray: Array = new Array ();
var colorsArray: Array = new Array ();

A loop will be used to access data contained within the matrix, but before creating another array facing the sample code. This is the section that makes this an advanced Flash CS3 Tutorial. The first line is the array that Flash CS3 Tutorial is all about. Next, is the loop that you should already know. Inside the loop is where the fun begins. The loop is in fact the creation of circles with a color from the first array and adding them to the cirArray so that they can be used later. First, a variable number is created and set to be a random number between 0 a 4, (see math tutorials) if you need a better understanding. The code then creates a new sprite (object) and the three after you use the graphical properties to create a circle (see control graphics tutorial) through the variable Sprite or cir.

var cirArray: Array = new Array ();
for (var i: int = 0; i 520) {
cirArray [i]. x = -20
cirArray [i]. y = Math.random () * 300
Else}
cirArray [i]. + X = 15
}
};

Again, add the sample code to the action panel. The first line of code is a simple function that is called from the start button. Next, is the loop that moves through the array. It is possible to change the number 15 for the length of the matrix and replacing it with cirArray.lenght would automatically detect the length of the array. So, it's a statement checks to see if the object contained with the specific index of the array is on stage. If the object is in phase, moves the object 15 pixels, and if it is not the scene is moved to the other side of the scene and changes the y position. This simple if statement is what makes the 15 simple circles seem to be an infinite amount.

Press Control-Enter and test the movie, hopefully you have an animation created with Flash CS3 ActionScript arrays

Download Flash CS3 Tutorial, Source File

Flash CS3 Tutorials, FrenchSquared Copyright 2008...

No comments:

Post a Comment