Flash Education: The Matrix Special Effects

Home • Members Tutorials Forum iSnapChat Contact Us 


Flash Tutorials


Flash Tutorial - The Matrix Special Effects


Free Flash Tutorial

Step 8    <<   Previous      Intro   1   2   3   4   5   6   7   8   9   10     Next   >>      


Step Eight: The ActionScript Explained - Frame 1

Although some knowledge of actionscript is required the author and editors have tried to explain each function and it's implication in the script sequentially. For further assistance you can view the Reference panel (Shift + F1) to learn more about the ActionScript and it's syntax.

var SSX = 30;
var SSY = 30;
var XSPACING = 20;
var YSPACING = 20;

The above statements create four constants. The constants XSPACING and YSPACING are used for maintaining the minimum distance between adjacent alphabets. There would be XSPACING number or columns and YSPACING number or rows in your Movie.

var spans = new Array(SSX);

Creates an array named span with provision for SSX number of variables in it. The array will be empty at this point of time when the script is first executed.

for (y=0; y < SSY; y++) {
for (x=0; x < SSX; x++) {

Starts two for loops with one nested inside the other. A for loop consists of three parameters and statements to be executed within the curly braces {}. The first parameter is the initial condition, the second one being a expression which when true the statements have to be executed and finally the increment parameter that states in what steps the variable must be increased each time the loop is executed. Two new variables x and y are implicitly declared within the loop. The inner loop is executed SSX number of times and the outer loop is executed SSY number of times. But actually the inner loop is executed SSX * SSY number of times (30*30=900 times) since it is nested within the outer loop.

n = y*SSX+x;

Creates an integer n from the mathematical relation. This number is used to name the Movie Clips when they are duplicated in the next stage as well as to set depth for the Movie Clips. It takes a value ranging from 0 to 899.

if ((((x*5 ^ y*3)) & 3) == 0) {
duplicateMovieClip("myCharacters", "c"+n, n);

Evaluates the function(x*5 ^ y*3) first and then performs a 32-bit bitwise comparison of the result with the number '3', i.e. checks whether the result of the mathematical expression is equal to '3'. If the condition is false '0' is the result of comparison and when it is true '1' is the result of the comparison. This result is compared again with '0'. If(x*5 ^ y*3) is not equal to '3' the statements within the curly braces are executed, otherwise the following statements are evaluated.

The duplicateMovieClip creates an instance of a Movie Clip while the Movie is playing. The Movie Clip to be duplicated is mentioned (name of the instance of a Movie Clip) in the first parameter of the function within quotes. The new duplicated Movie Clip will be named according to the second parameter in the function and set at a depth specified in the third parameter for the function. The depth level is a stacking order for duplicated Movie Clips. This stacking order is much like the stacking order of layers in the Timeline; Movie Clips with a lower depth level are hidden under clips with a higher stacking order. You must assign each duplicated Movie Clip a unique depth level to prevent it from replacing Movies on occupied depths. Since n is unique for each value of x and y the depth and name of each Movie Clip is unique. The Movie Clips are named as c0, c1, c2, up to c899 when n takes the value from 0 to 899. The '+' symbol joins the alphabet "c" with the integer n to name the Movie Clip.

/* Only add the following code (by removing the "//") if you have created individual MCs for specific letters such as A, B, C & D etc. Note the first Instance Name would go in the line above instead of: myCharacters The rest of the go in the lines below. Change my Instance Names to match yours. */

// } else if ((((x*5 ^ y*3)) & 4) == 0) {
// duplicateMovieClip("myMC_B", "c"+n, n);

/* If you have more MCs, repeat the two lines of code as necessary incrementing the count like this:  */

// } else if ((((x*5 ^ y*3)) & 5) == 0) {
// duplicateMovieClip("myMC_C", "c"+n, n);

/* Your very last MCs Instance Name would go in the line below instead of:
myCharacters  */

You only need the code above if you are using several Movie Clips each with their own Instance name. You use the code by removing the double slash // comment tags at the beginning of the lines. This script is similar in functioning as stated above except the fact that it us used to generate Movie Clips of other instances as named. The algebraic expression is used as a random function to choose between the different Movie Clips and duplicate them. If you are good at algebra you can design your own expression to choose the Movie Clips to be duplicated.

else {
duplicateMovieClip("myCharacters", "c"+n, n);

The last option of the if .. else statement is shown above. The Movie Clip mentioned here will be duplicated by default if all other expressions turn out to be false since there is no expression to be evaluated here.

with (this["c"+n]) {
_y = y*YSPACING;

The above script allows you to specify an object (such as a Movie Clip) and evaluate expressions and actions pertaining to that object. This prevents you from having to repeatedly write the object's name or the path to the object. The statement this["c"+n] allows you to refer to the most recent Movie Clip that you duplicated and renamed. The _x and _y are x and y co-ordinates of the Movie Clip, i.e. the position of the Movie Clip in the screen. These are set to a new value so that no two Movie Clips overlap each other.

for (x=0; x < SSX; x++) {
y = Math.random()*SSY*8;
spans[x] = -(int(y));

The above loops generates a value for the variable y from the expression Math.random()*SSY*8 and stores these values in the array spans. The function Math.random() randomly generates a number 'n' where 0 < n < 1. The range of values y can take is 0 < y < 240 including fractions. The fractions are rounded off to the nearest integer using the int function.

The entire script in the first frame is executed only once. The Movie Clips are duplicated and placed in appropriate positions in the screen but are invisible, since in all Movie Clips the first frame was a blank keyframe with the stop(); function that would pause the Movie Clips in that frame. It was only in the second frame of each Movie Clip that the text was visible. The Movie would appear as shown below if the first frame of each Movie Clip had the stop(); function in the frame where the text first appears (instead of a blank keyframe).

Example: Download the Flash file Int 143b


Step 8    <<   Previous      Intro   1   2   3   4   5   6   7   8   9   10     Next   >>      

50835 visitors to this page since 11 May 07 •

Phil Schulz's Facebook Profile
Webwasp is Phil Schulz's baby. You are welcome to contact me or become my Facebook friend: Click here

 Top of Page HomeMembers Tutorials Forum iSnapChat Contact Us 
 All material on this site is protected under international copyright © law. DO NOT reproduce any material from this site without written permission. Please ask as permission is often granted.