Hey all,
Here is the situation I'm working on.....
I am creating a .swf file that receives it's data from an external text file.
The file consists of the following fields:
- An MC that serves as a placeholder for .jpg images
- A dynamic text box to contain the caption of the .jpg image currently displayed.
Once all is loaded, two buttons (prev & next) will allow the user to cycle through the array of pictures (each with a different caption connected with the picture).
I am successful in getting the data loaded into the array, but I am not sure how to move up and down the array (using the prev & next buttons) to accomplish my goal.
I am still way new at this so any help would be majorly appreciated!
Oh....and if the code in and of itself looks awkward...please let me know.
Thanks in advance!
Here is the code (I have also attached a .zip file of the project):
__________________________________________________ _________
Code:
// initialise the variables we need
// path to the pictures with the text file.
picPath = "Images/";
// disable the buttons initially
next_btn.enabled = false;
next_btn._alpha = 20;
prev_btn.enabled = false;
prev_btn._alpha = 20;
// array that will hold the filename of the picture
picArray = new Array();
// array that will hold the caption of the picture
captionArray = new Array();
// create new loadVars object
newLoadVars = new LoadVars();
// retrieve the textfile
newLoadVars.load("data.txt");
// put the data in the textfield
newLoadVars.onLoad = function(success) {
if (success) {
trace("LoadVars routine successfull");
_root.pics = this.picCollection.split(",");
_root.captions = this.picCaptions.split(",");
_root.maxPics = picArray.length;
_root.maxCaptions = captionArray.length;
//enable 'next' button following successful loading of external text file.
next_btn.enabled = true;
next_btn._alpha = 100;
} else {
getURL("javascript:alert('Could not load the requested textfile');");
}
};
// defining the action for the buttons
next_btn.onRelease = function() {
//once the user clicks on the 'next' button the first time, the previous button can now become active.
prev_btn.enabled = true;
prev_btn._alpha = 100;
for (i=0; i<maxPics; i++) {
getPicture;
getCaption;
//if we reach the end of the array, disable the next button
if (i=maxPics) {
next_btn.enabled = false;
next_btn._alpha = 20;
}
}
};
//temporarily commented out for troubleshooting
//prev_btn.onRelease = function() {
//getPicture(picArray[picCounter]);
//getCaption(picArray[picCounter]);
//picCounter--;
//};
// function that deals with the display of pictures
//
function getPicture() {
picHolder_mc.loadMovie(picPath+picArray[i]);
}
// function that deals with displaying captions
function getCaption() {
captions_txt.text = captionArray[i];
}