Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-08-2004, 02:45 AM   #1
asWarrior
Registered User
 
Join Date: Apr 2004
Posts: 7
Question Need help with 'next' / 'prev' buttons when traversing an array

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];
}
Attached Files
File Type: zip slideshow.zip (492.8 KB, 160 views)

Last edited by asWarrior; 04-08-2004 at 04:01 PM.
asWarrior is offline   Reply With Quote
Old 04-08-2004, 04:08 AM   #2
Billy T
Oops I did it again
 
Billy T's Avatar
 
Join Date: Oct 2001
Location: Melbourne
Posts: 8,579
Default

try

//var used to count through array
i=0;
// 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;
if (i<maxPics) {
i++;
getPicture();
getCaption();
}else{
//if we reach the end of the array, disable the next button
next_btn.enabled = false;
next_btn._alpha = 20;
}

};
function getPicture() {
picHolder_mc.loadMovie(picPath+picArray[i]);
}
// function that deals with displaying captions
function getCaption() {
captions_txt.text = captionArray[i];
}
__________________
Billy
Online Galleries
iPhone Safety App - iStaySafe
Free Flash Video Tutorials
Photo Website Template

Don't email or PM me questions...
Billy T is offline   Reply With Quote
Old 04-08-2004, 03:22 PM   #3
asWarrior
Registered User
 
Join Date: Apr 2004
Posts: 7
Default Excellent!

So far so good! Thanks for the help BillyT.....it cycles through 'forward' nicely.

Last edited by asWarrior; 04-08-2004 at 07:33 PM.
asWarrior is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:46 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.