Strange function problem

OK, I’ve created my own photo gallery that loads all the images in through an XML file called “imageList.xml”. The whole XML thing works fine and the “Next” and “Previous” buttons work by calling functions. However, I want to call the “showNextPics” function as soon as the movie loads. Here’s my code on the first frame (it’s a one-frame timeline):


// initialize variables and arrays
_root.imagesFilename = new Array();
_root.currentImage = 0;
// hide previous button to begin with
_root.prevButton._visible = false;
// define functions
function pushArray() {
_root.totalImages = objXML.firstChild.childNodes.length;
for (var count = 0; count < _root.totalImages; count++) {
nodeObj = objXML.firstChild.childNodes[count];
_root.imagesFilename[count] = nodeObj.attributes.filename;
}
}
function loadXML(success) {
if (success) {
pushArray();
} else {
}
}
function showNextPics() {
_root.prevButton._visible = true;
for (i=0; i < 999; i++) {
_root["image"+i].removeMovieClip();
}
xpos = 0;
ypos = 0;
for (i=_root.currentImage; i < _root.currentImage+6; i++) {
if (i < _root.totalImages) {
_root.attachMovie("pictureClip","image"+i,i);
_root["image"+i].pictureFrame.loadMovie(_root.imagesFilename*);
_root["image"+i].pictureFrame.picNumber.text = i;
_root["image"+i]._x = xpos;
_root["image"+i]._y = ypos;
xpos += 160;
if (xpos > 160) {
	xpos = 0;
	ypos += 110;
}
} else {
_root.nextButton._visible = false;
}
}
_root.currentImage += 6;
if (i >= _root.totalImages) {
_root.nextButton._visible = false;
}
}
function showPrevPics() {
_root.nextButton._visible = true;
for (i=0; i < 999; i++) {
_root["image"+i].removeMovieClip();
}
xpos = 0;
ypos = 0;
for (i=_root.currentImage-12; i < _root.currentImage-6; i++) {
_root.attachMovie("pictureClip","image"+i,i);
_root["image"+i].pictureFrame.loadMovie(_root.imagesFilename*);
_root["image"+i].pictureFrame.picNumber.text = i;
_root["image"+i]._x = xpos;
_root["image"+i]._y = ypos;
xpos += 160;
if (xpos > 160) {
xpos = 0;
ypos += 110;
}
if (i == 0) {
_root.prevButton._visible = false;
}
}
_root.currentImage -= 6;
if (i < -1) {
_root.prevButton._visible = false;
}
}
// load XML doc
objXML = new XML();
objXML.onLoad = loadXML;
objXML.ignoreWhite = true;
objXML.load("imageList.xml");
 
// HERE'S THE PROBLEM
showNextPics();

Does anyone know why the function won’t call straight away. It works fine when I click on the “next” button with the following code on it:


on (release) {
showNextPics();
}

It just seems weird I’ve done some pretty advanced Actionscripting and I can’t get this final, one little thing to work!!

Any help would be greatly appreciated,
Dave