Learn Flash: Array

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Intro to Arrays

 

Free Flash Tutorial


Example B    <<   Previous      Intro   A   B   C   D     Next   >>       >>   Webwasp Mates

 

Arrays: Example B

In the example below there is a single button that goes through the Array listing in order and then goes back to the beginning and starts again. In other words it is a loop.

Example: Download the Flash file  Int 128b


A single button that scrolls through the listing in a circular fashion.

This Movie displays a variable called myNumber. This is the number that keeps count of your position in the listing and is then used to call the next listing. Ordinarily you would not display this number. I have only done so as it is easier to see what the ActionScript is doing.


Example B - Step One: Building the Movie

Building the Movie is exactly the same as in Step One of the previous example (A), except that this time the Movie only has one button. Because there is only one button, the default text is marginally different:


Default start up text is different.


Example B - Step Two: Building the Array

Place the same ActionScript in frame 1 of the Movie as you did in the previous example. This time there is one additional line:

var myArray = new Array();
myArray[0] = "You can have text or a number here or anything you like really!";
myArray[1] = "More text here.";
myArray[2] = "A number here: 123";
myArray[3] = "Other stuff";
myNumber = 0;

The additional line introduces a variable called myNumber which will be counted. This is so that the Flash Movie knows where you are up to in the Array. As you can see, it is set to zero which is the first listing in the Array.


Example B - Step Three: The Button ActionScript

The ActionScript for the button is as follows:

//  On release of the Mouse button do the following...
on
(release) {

    //  Set myText to the same as myNumber in the Array
    myText = myArray[myNumber];

    //  If myNumber is 3 then...
    if (myNumber == 3) {

        //  Reset myNumber to zero
        myNumber = 0;

    //  Otherwise...
    } else {

        //  Add one to myNumber
        myNumber = myNumber+1;

    //  Close the if-else statement
    }

// Close the on(release) statement
}


When you click the button, the ActionScript sets the Array to the variable myNumber. It then checks to see if myNumber is 3. If it is 3, it resets myNumber to 0. If it is not three it adds 1 to myNumber.

         

Example B    <<   Previous      Intro   A   B   C   D     Next   >>       >>   Webwasp Mates


Webwasp Community: Webwasp Mates & Dates

Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates

 Top of Page Home Food Mates Members Tutorials Forum Buy Templates 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.