# Function within XML loop problems

**URL:** <https://forum.kirupa.com/t/function-within-xml-loop-problems/166534>\
**Category:** programming\
**Created:** [October 20, 2005, 6:40pm UTC](https://forum.kirupa.com/t/function-within-xml-loop-problems/166534 "2005-10-20T18:40:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![knappster](https://avatars.discourse-cdn.com/v4/letter/k/67e7ee/32.png) [@knappster](https://forum.kirupa.com/u/knappster)\
**Post date:** [October 20, 2005, 6:40pm UTC](https://forum.kirupa.com/t/function-within-xml-loop-problems/166534/1 "2005-10-20T18:40:56Z")

</div>

I have loaded my xml. Works great.

I have set up my ‘for’ loop. Perfect.

Now I’d like to, from the ‘for’ loop, set up an external MC’s onPress function. If I trace - for example - (interactiveNode\*.childNodes[0]😉 outside of the function properties, it works great. If I move that same code inside of the function, it returns “undefined”.

How could I set this up to run a loop within the function?

Here is some code:

```auto

var interactive_xml:XML = new XML();
interactive_xml.ignoreWhite = true;
interactive_xml.onLoad = function(success:Boolean):Void {
    if (success) {
		var interactiveLength:Number = interactive_xml.firstChild.childNodes.length;
		var interactiveNode = interactive_xml.firstChild.childNodes;
		portfolioPieceButton.pieceTitleMC.pieceTitle.htmlText = "";
		this.createEmptyMovieClip(interactivePortfolio, i)
		for (var i = 0; i<interactiveLength; i++) {
			//This does work, but this isn't where I want it to work
			trace(_root[interactiveNode*.childNodes[6].firstChild.nodeValue);
			_parent.portfolioMCInteractive["interactivePieceButton"+*].onPress = function() {
				//This DOESN'T work, but it is where i need it to! :(
				trace(_root[interactiveNode*.childNodes[6].firstChild.nodeValue);
			}
		}
    } else {
        trace("tiny error");
    }
};

interactive_xml.load("myxml.xml");

```

Thank you 🙂 :puzzled:
