Learn Flash: Array

Home Food Mates • Members Tutorials Forum Buy Templates Contact Us 

 


Flash Tutorials

   

Flash Tutorial - Intro to Arrays

 

Free Flash Tutorial


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

 

Arrays: Example C

In this example there is a back and forward button to scroll through the listings. It also tells you when you have come to the end or beginning of the listing, so that you will know to go back the other way. It does not start at the beginning, which would be number 0 but at the number 2 listing.

This Movie also displays the variable called myNumber. As with the previous example this number keeps count of your position in the listing and is then used to call the next (or previous) 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: Download the Flash file  Int 128c


Two buttons enable the user to select to scroll either forward or backwards.

Note: Keep clicking past the end (or start) of the listing. You will notice that myNumber keeps counting up (or down) even though you have got to the end (or beginning) of the listings. This may seem strange at first, but it is more work to stop the number at the correct place, than to let it keep counting. Remember that ordinarily the user would not see this number.

Example C - Step One: Building the Movie

Building the Movie is exactly the same as in Step One of the first example (A), except that this time the Movie only has two buttons. I have also selected slightly different buttons: I have used the Next and Previous buttons from the Circle set of buttons in the Common Library.


Example C - Step Two: Building the Array

The Array is set up in frame one of the Movie, in exactly the same fashion as the example (B). The only difference is that this time I have set myNumber to 2. This means that the Array will start in the middle. This means that initially the user can click either backwards or forwards.

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 = 2;


Example C - Step Three: The button ActionScript

The Back button ActionScript

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

    // Subtract 1 from myNumber
    myNumber = myNumber-1;

    // If myNumber is less than 0 then...
    if (myNumber< 0) {

        // Display the following message
        myText = "You cannot go back any further !!!";

    // If myNumber is greater than 3 then...
    } else if (myNumber>3) {

        // Reset myNumber to 3 and ...
        myNumber = 3;

        // Display the Array listing for myNumber (which is 3)
        myText = myArray[myNumber];

    // Otherwise ...
    } else {

        // Display the Array listing for myNumber
        myText = myArray[myNumber];

    // Close 'if else' statement
    }

// Close on(release) statement
}

What this does is:

 

The Forward Button ActionScript

This is just the opposite of the above:

// On release of the Mouse Button
on (release) {

    
// Add 1 to my number
    myNumber = myNumber+1;

    
// If myNumber is greater than 3 then...
    
if (myNumber>3) {

        
// Display the following
        myText =
"This Array is Finished !!";

    
// If myNumber less than 0 then...
    }
else if (myNumber < 0) {

        
//Reset myNumber to: 0 and ...
        myNumber = 0;

        
// Display the Array listing for myNumber (which is 0)
        myText = myArray[myNumber];

    
// Otherwise ...
    }
else {

        
// Display the Array listing for myNumber
        myText = myArray[myNumber];

    
// Close if-else statement
    }

// Close on(release) statement
}

         

Example C    <<   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.