# Loop function help?

**URL:** <https://forum.kirupa.com/t/loop-function-help/142446>\
**Category:** Uncategorized\
**Created:** [March 28, 2005, 11:00pm UTC](https://forum.kirupa.com/t/loop-function-help/142446 "2005-03-28T23:00:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imported\_East\_High](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/imported_east_high/32/1331_2.png) [@imported\_East\_High](https://forum.kirupa.com/u/imported_East_High)\
**Post date:** [March 28, 2005, 11:00pm UTC](https://forum.kirupa.com/t/loop-function-help/142446/1 "2005-03-28T23:00:47Z")

</div>

Hey Again,  
I’m dealing with this bit of code that loads images via XML. I’m trying to write a loop function, but I need help. If this post is too long, let me know and I’ll post the .fla  
Okay, here goes…

This is the bit of XML that defines the array:

```auto
p = 0;
function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		total = xmlNode.childNodes.length;
		for (i=p; i<total; i++) {
			image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
		}
		firstImage();
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("backgrounds.xml");

```

This is the function that loads the first image:

```auto
function firstImage() {
	loadPic(image[p]);
	fadingSymbol_mc.gotoAndStop(1);
}

```

And this is the function that loads the next image in the array:

```auto
function nextImage() {
	this.onEnterFrame = function() {
		if (p<(total-1)) {
			fadingSymbol_mc.prevFrame();
		}
		if (fadingSymbol_mc._currentframe == 1) {
			fadingSymbol_mc._alpha = 0;
			p++;
			loadPic(image[p], 1);
			fadingSymbol_mc.gotoAndStop(1);
			delete this.onEnterFrame;
		}
	};
}

```

It would seem that there should be another “if” statement in the “nextImage” function if I want it to loop back to the first image, right? One that says something like: if (p==(total)) then play the firstImage function. I’ve tried everything that I can think of, but no luck. Can anyone help me? :hurt:
