# Multiple XML photo gallery thumbnails question

**URL:** <https://forum.kirupa.com/t/multiple-xml-photo-gallery-thumbnails-question/280699>\
**Category:** flash\
**Created:** [January 30, 2009, 2:57pm UTC](https://forum.kirupa.com/t/multiple-xml-photo-gallery-thumbnails-question/280699 "2009-01-30T14:57:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![naturesrat](https://avatars.discourse-cdn.com/v4/letter/n/2bfe46/32.png) [@naturesrat](https://forum.kirupa.com/u/naturesrat)\
**Post date:** [January 30, 2009, 2:57pm UTC](https://forum.kirupa.com/t/multiple-xml-photo-gallery-thumbnails-question/280699/1 "2009-01-30T14:57:34Z")

</div>

Hi, i’m looking for some quick help with my photo gallery

I have it set up to load multiple XML files, but, when you select a new book/xml, i want it the thumbnails to refresh starting with thumbnail #1, instead of wherever it left off in the array

this obviously has something to do with the variable k, but i am having a lot of trouble figuring out where to fix this at.

sorry if this is super obvious, and thanks in advance for your help!

> 

// Buttons to call each Gallery and reload data

bookone\_btn.onRelease = function() {  
xmlURL = “book1.xml”; // sets xml file  
xmlLoader(); // loads xml data  
thumbnails\_fnRemove(k); // clear old thumbnails  
thumbnails\_fn(k); // populate new thumbnails  
};

booktwo\_btn.onRelease = function() {  
xmlURL = “book2.xml”; // sets xml file  
xmlLoader(); // loads xml data  
thumbnails\_fnRemove(k); // clear old thumbnails  
thumbnails\_fn(k); // populate new thumbnails  
};

portfolio\_btn.onRelease = function() {  
xmlURL = “book2.xml”; // sets xml file  
xmlLoader(); // loads xml data  
thumbnails\_fnRemove(k); // clear old thumbnails  
thumbnails\_fn(k); // populate new thumbnails  
};

//------------------------------------------------------

// load starting gallery xml  
xmlURL = “book1.xml”;  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(xmlURL);

// function to call gallery xml after xmlURL stated by buttons  
function xmlLoader() {  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.load(xmlURL);  
xmlData.onLoad = loadXML;  
};

delay = 1000;

var curLength;  
function loadXML(loaded) {  
//reset p  
p = 0;  
//remove old thumbs  
for (var j = 0; j\<curLength; j++) {  
thumbnail\_mc[“t”+j].removeMovieClip();  
}  
if (loaded) {  
xmlNode = this.firstChild;  
image = ;  
thumbnails = ;  
total = xmlNode.childNodes.length;  
for (i=0; i\<total; i++) {  
image\* = xmlNode.childNodes\*.childNodes[0].firstChild.nodeValue;  
thumbnails\* = xmlNode.childNodes\*.childNodes[1].firstChild.nodeValue;  
thumbnails\_fn(i);

```
    }
    //changes
    firstImage();
    //set curLength
    curLength = total;        
} else {
    content = "file not loaded!";
}

```

}

//navigation for keyboards arrow keys  
listen = new Object();  
listen.onKeyDown = function() {  
if (Key.getCode() == Key.LEFT) {  
prevImage();  
clearInterval(myInterval);  
}  
if (Key.getCode() == Key.RIGHT) {  
nextImage();  
clearInterval(myInterval);  
}  
if (Key.getCode() == Key.DOWN) {  
clearInterval(myInterval);  
slideshow();  
}  
if (Key.getCode() == Key.UP) {  
clearInterval(myInterval);  
}  
};

//navigation for next/prev buttons  
Key.addListener(listen);  
previous\_btn.onRelease = function() {  
prevImage();  
};  
next\_btn.onRelease = function() {  
nextImage();  
};  
play\_btn.onRelease = function() {  
nextImageSlide();  
};  
pause\_btn.onRelease = function() {  
clearInterval(myInterval);  
};

// image preloader  
p = 0;  
this.onEnterFrame = function() {  
filesize = picture.getBytesTotal();  
loaded = picture.getBytesLoaded();  
preloader.\_visible = true;  
if (loaded != filesize) {  
preloader.preload\_bar.\_xscale = 100\*loaded/filesize;  
} else {  
preloader.\_visible = false;  
if (picture.\_alpha\<100) {  
picture.\_alpha += 10;  
}  
}  
};

var myInterval;

// next and previous image navigation  
function nextImage() {  
if (p\<(total-1)) {  
p++;  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
picture\_num();  
clearInterval(myInterval);  
}  
}  
}

function nextImageSlide() {  
if (p\<(total-1)) {  
p++;  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
picture\_num();  
clearInterval(myInterval);  
slideshow();  
}  
}  
}

function prevImage() {

```
clearInterval(myInterval);

```

slideshow();

if (p\>0) {  
p–;  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
picture\_num();  
}  
}

function firstImage() {  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[0], 1);  
picture\_num();  
clearInterval(myInterval);  
}  
}

function picture\_num() {  
current\_pos = p+1;  
pos\_txt.text = current\_pos+" / "+total;  
}

function slideshow() {  
myInterval = setInterval(pause\_slideshow, delay);  
function pause\_slideshow() {  
clearInterval(myInterval);  
if (p == (total-1)) {  
p = 0;  
firstImage();  
} else {  
nextImageSlide();  
}  
}  
}

function thumbNailScroller() {  
// thumbnail code!  
this.createEmptyMovieClip(“tscroller”, 504);  
scroll\_speed = 20;  
tscroller.onEnterFrame = function() {  
if ((\_root.\_xmouse\>=thumbnail\_mc.\_x) && (\_root.\_xmouse\<=thumbnail\_mc.\_x+thumbnail\_mc.\_width)) {  
if ((\_root.\_ymouse\>=(hit\_right.\_y-120)) && (thumbnail\_mc.hitTest(hit\_right))) {  
thumbnail\_mc.\_y -= scroll\_speed;  
} else if ((\_root.\_ymouse\<=(hit\_left.\_y+120)) && (thumbnail\_mc.hitTest(hit\_left))) {  
thumbnail\_mc.\_y += scroll\_speed;  
}  
} else {  
delete tscroller.onEnterFrame;  
}  
};  
}

// function to clear thumbnails from scroller ready for ready for loaded xml data  
function thumbnails\_fnRemove(k) {  
target\_mc.removeMovieClip();  
removeMovieClip(thumbnail\_mc.t(+k));

}

// function to load new thumnails into scroller from loaded xml  
function thumbnails\_fn(k) {  
thumbnail\_mc.createEmptyMovieClip(“t”+k, thumbnail\_mc.getNextHighestDepth());  
tlistener = new Object();  
tlistener.onLoadInit = function(target\_mc) {  
target\_mc.\_y = hit\_left.\_y-117+(target\_mc.\_height+5)\*k;

target\_mc.pictureValue = k;  
target\_mc.onRelease = function() {  
p = this.pictureValue-1;  
nextImage();  
};  
target\_mc.onRollOver = function() {  
this.\_alpha = 50;  
thumbNailScroller();  
};  
target\_mc.onRollOut = function() {  
this.\_alpha = 100;  
};  
};  
image\_mcl = new MovieClipLoader();  
image\_mcl.addListener(tlistener);  
image\_mcl.loadClip(thumbnails[k], “thumbnail\_mc.t”+k);  
}
