# XML gallery problem with back button

**URL:** <https://forum.kirupa.com/t/xml-gallery-problem-with-back-button/205245>\
**Category:** flash\
**Created:** [October 27, 2006, 11:54am UTC](https://forum.kirupa.com/t/xml-gallery-problem-with-back-button/205245 "2006-10-27T11:54:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kathari](https://avatars.discourse-cdn.com/v4/letter/k/a183cd/32.png) [@kathari](https://forum.kirupa.com/u/kathari)\
**Post date:** [October 27, 2006, 11:54am UTC](https://forum.kirupa.com/t/xml-gallery-problem-with-back-button/205245/1 "2006-10-27T11:54:49Z")

</div>

HI,  
I have adapted the XML gallery here on Kirupas [(photogallery)](http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm) which has been working very well.  
Now I am doing another one and I am having trouble with the back button.  
When clicking it the first time keeps going forward insteda of changing to go back. After that it works backwards as intended but I can’t go all the way back to the first picture because the numbering § is wrong due to the first error. I don’t manage to see where I am going wrong.  
Here are the codes. I have kept the traces.  
First the XML-code:[AS]function loadXML1(loaded) {  
if (loaded) {  
xmlNode1 = this.firstChild.firstChild;  
thumbnumber1 = [];  
image1 = [];  
description1 = [];  
total1 = xmlNode1.childNodes.length;  
for (i=0; i\<total1; i++) {  
thumbnumber1\* = xmlNode1.childNodes\*.childNodes[0].firstChild.nodeValue;  
image1\* = xmlNode1.childNodes\*.childNodes[1].firstChild.nodeValue;  
description1\* = xmlNode1.childNodes\*.childNodes[2].firstChild.nodeValue;  
}  
loadFirst1(image1[0], description1[0]);  
} else {  
bild\_txt.htmlText = “file not loaded!”;  
}  
}  
xmlData1 = new XML();  
xmlData1.ignoreWhite = true;  
xmlData1.onLoad = loadXML1;  
xmlData1.load(“gallery1Data.xml”);  
// ///////////////////////////////////  
// ///////////////////////////////////  
p = 0;  
function loadFirst1(pic, desc) {  
p++;  
maskOut(pic, desc);  
picture\_num1();  
}  
function loadNext1(pic, desc) {  
trace("before p++ "+p);  
if (p\<(total1)) {  
p++;  
trace(“second trace “+p);  
maskOut(pic, desc);  
picture\_num1();  
}  
}  
function loadPrevious1(pic, desc) {  
if (p\>0) {  
trace(p+” before p–”);  
p–;  
trace("third trace "+p);  
maskOut(pic, desc);  
trace("fourth trace “+p);  
picture\_num1();  
}  
}  
function picture\_num1() {  
current\_pos = p+1;  
pos\_txt.text = current\_pos+” / "+total;  
}[/AS]and the functions:[AS]function maskOut(pic, desc) {  
imageMC.imageMask.onEnterFrame = function() {  
this.newy = -514;  
if (this.\_y\<=-513) {  
picLoader(pic);  
imageMC.desc\_txt.text = desc;  
delete this.onEnterFrame;  
}  
};  
}  
function picLoader(pic) {  
imageMC.picContainer.loadMovie(pic);  
var clip = this.createEmptyMovieClip(“theLoader”, this.getNewDepth());  
clip.onEnterFrame = function() {  
var t = \_root.imageMC.picContainer.getBytesTotal();  
var l = \_root.imageMC.picContainer.getBytesLoaded();  
if (t == l && \_root.imageMC.picContainer.\_height\>0 && \_root.imageMC.picContainer.\_width\>0) {  
\_root.imageMC.picContainer.\_x = Stage.width-\_root.imageMC.picContainer.\_width;  
\_root.imageMC.picContainer.\_y = (Stage.height/2)-\_root.imageMC.picContainer.\_height/2;  
maskIn();  
delete this.onEnterFrame;  
}  
};  
}  
function maskIn() {  
imageMC.imageMask.newy = 0;  
}[/AS]and here is the button-code:[AS]nextMC.onRelease = function() {  
switch (true) {  
case \_currentframe == 2 :  
loadNext1(image1[p], description1[p]);  
break;  
case \_currentframe == 3 :  
loadNext2(image2[p], description1[p]);  
break;  
case \_currentframe == 4 :  
loadNext3(image3[p], description1[p]);  
break;  
case \_currentframe == 5 :  
loadNext4(image4[p], description1[p]);  
break;  
case \_currentframe == 6 :  
loadNext5(image5[p], description1[p]);  
break;  
case \_currentframe == 7 :  
loadNext6(image6[p], description1[p]);  
break;  
case \_currentframe == 8 :  
loadNext7(image7[p], description1[p]);  
break;  
}  
};  
backMC.onRelease = function() {  
switch (true) {  
case \_currentframe == 2 :  
loadPrevious1(image1[p], description1[p]);  
break;  
case \_currentframe == 3 :  
loadPrevious2(image2[p], description2[p]);  
break;  
case \_currentframe == 4 :  
loadPrevious3(image3[p], description3[p]);  
break;  
case \_currentframe == 5 :  
loadPrevious4(image4[p], description4[p]);  
break;  
case \_currentframe == 6 :  
loadPrevious5(image5[p], description5[p]);  
break;  
case \_currentframe == 7 :  
loadPrevious6(image6[p], description6[p]);  
break;  
case \_currentframe == 8 :  
loadPrevious7(image7[p], description7[p]);  
break;  
}  
};[/AS]Also attaching the XML-document.  
If you want me to send pictures, I’ll take the time to do that.
