Here's the working code:
//--------load in XML--------//
var x:XML = new XML();
x.ignoreWhite = true;//ignores white space in xml document
var urls:Array = new Array();//stores all urls for photos
var captions:Array = new Array();//holds captions read from xml
var currentImage:Number; //keeps track of which photo is currently being displayed (index number)
x.onload = function() {
var photos:Array = this.firstChild.childNodes; //firstChild = root element of xml document - childnodes returns array of all nested elements within there
for (i=0;i<photos.length;i++) { //iterates through photos to process them
urls.push(photos[i].attributes.url); //put url and caption into arrays - "push" tags onto end of array
captions.push(photos[i].attributes.caption);
}
holder.loadMovie(urls[0]); //loads first pic
caption.text = captions[0];//gives first element for when first go into movie
currentImage = 0; //because first photo is displayed
}
x.load("folio.xml");
//--------Set up buttons--------//
previous.onRelease = function() { //prevoius button
if(currentImage > 0) { //if first photo is being displayed don't want previous button to do anything
currentImage--; //decrement by one (subtract one from who is on)
holder.loadMovie(urls[currentImage]);//load new photo into holder
caption.text = captions[currentImage];
}
}
next.onRelease = function() { //prevoius button
if(currentImage < urls.length-1) { //.length tell how many in xml - -1 for array index number
currentImage++; //increment by one (subtract one from who is on)
holder.loadMovie(urls[currentImage]);
caption.text = captions[currentImage];
}
}
Here's the code where the back button fails:
//--------load in XML--------//
var x:XML = new XML();
x.ignoreWhite = true;//ignores white space in xml document
x.load("folio.xml");
var urls:Array = new Array();//stores all urls for photos
var captions:Array = new Array();//holds captions read from xml
var currentImage:Number;//keeps track of which photo is currently being displayed (index number)
x.onload = function() {
var photos:Array = this.firstChild.childNodes; //firstChild = root element of xml document - childnodes returns array of all nested elements within there
for (i=0; i<photos.length; i++) { //iterates through photos to process them
urls.push(photos[i].attributes.url);//put url and caption into arrays - "push" tags onto end of array
captions.push(photos[i].attributes.caption);
}
_root.createEmptyMovieClip("holder", 1);//create the mc into which photos go
holder._x = holder._y=220;//image position
holder.loadMovie(urls[0]); //loads first pic (index number 0)
caption.text = captions[0]; //loads first caption to go with image
currentImage = 0; //because first photo is displayed
};
//--------Set up buttons--------//
next.onRelease = function() { //next button
if(currentImage < urls.length-1) { //.length tell how many in xml - -1 for array index number
currentImage++; //increment by one (subtract one from who is on)
holder.loadMovie(urls[currentImage]);
caption.text = captions[currentImage];
}
}
previous.onRelease = function() { //prevoius button
if(currentImage > 0) { //if first photo is being displayed don't want previous button to do anything
currentImage--; //decrement by one (subtract one from who is on)
holder.loadMovie(urls[currentImage]);//load new photo into holder
caption.text = captions[currentImage];
}
}
Why doesn't this work?

New Topic/Question
Reply


MultiQuote




|