|
||||||
|
||||||
Flash Tutorial - Intro to Arrays

Free
Flash Tutorial
Arrays: Example D
This is a better solution than the previous example (C). In this example there is also a back and a forward button to scroll through the listings. If you are at the beginning of the listings, the back button disappears and if you are at the end of the listing the forward button disappears. This means that you do not have to display a silly message like: You are at the end!
You cannot get beyond the end of the listings as the buttons
are not available to press!
Example: Download
the Flash file Int 128d
Buttons enable the
user to go either forward or backwards.
Note: Remember that ordinarily the user would not see the myNumber display.
Example D - Step One: Building the Movie
Building the Movie is similar to in Step One of the first example (A), except that this time the Movie only has two buttons. There is also one other important difference:
You give the button an Instance name in the Property Inspector.
Example D - Step Two: Building the Array
The Array is set up in frame one of the Movie in exactly the same fashion as in example C. The only difference is:
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;
// Makes the Back button invisible
back._visible = 0;
Example D - Step Three: The Button ActionScript
The Back Button
// On release of the Mouse Button
on (release) {
// Subtract 1 from my number
myNumber = myNumber-1;
// If myNumber is equal to or less than 0 then...
if (myNumber <= 0) {
// Display the following
myText = myArray[myNumber];
// Makes the back button invisible
back._visible = 0;
// Makes the forward button visible
forward._visible = 1;
// If myNumber is greater than or equal to 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];
// Makes the back button visible
back._visible = 1;
// Makes the forward button invisible
forward._visible = 0;
// Otherwise ...
} else {
//
Display the Array listing for myNumber
myText = myArray[myNumber];
// Makes the back button visible
back._visible = 1;
// Makes the forward button visible
forward._visible = 1;
// Close if-else statement
}
// Close on(release) statement
}
The Forward Button
// 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) {
//
Resets myNumber to 3
myNumber = 3;
// Display the Array listing for myNumber (which is 3)
myText = myText = myArray[myNumber];;
// Makes the back button visible
back._visible = 1;
// Makes the forward button invisible
forward._visible = 0;
// If myNumber is equal to or 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];
// Makes the back button invisible
back._visible = 0;
// Makes the forward button visible
forward._visible = 1;
// Otherwise ...
} else {
//
Display the Array listing for myNumber
myText = myArray[myNumber];
// Makes the back button visible
back._visible = 1;
// Makes the forward button visible
forward._visible = 1;
// Close if-else statement
}
// Close on(release) statement
}
That's it. I hope you are now an Array Whiz!
|
Why not try out webwasp's new community. Meet new people, find friends in your area: Webwasp Mates & Dates
|
|
|
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.
|