# AS2 create xml in function refer from outside function

**URL:** https://forum.kirupa.com/t/as2-create-xml-in-function-refer-from-outside-function/289065
**Category:** flash
**Created:** [May 26, 2009, 12:44am UTC](https://forum.kirupa.com/t/as2-create-xml-in-function-refer-from-outside-function/289065 "2009-05-26T00:44:47Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![gilesrulz](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@gilesrulz](https://forum.kirupa.com/u/gilesrulz)
#### Post date: [May 26, 2009, 12:44am UTC](https://forum.kirupa.com/t/as2-create-xml-in-function-refer-from-outside-function/289065/1 "2009-05-26T00:44:47Z")

</div>

I need to create a new xml from within a function, then refer to it outside of that function.

example:

```auto
function xmlIt(array) {
	var results_xml = new XML();
	results_xml.ignoreWhite = true;
	xmlString = toXMLString(array);
	results_xml.parseXML(xmlString);
	trace(results_xml);
	
}

function toXMLString(toXML) {
	var xmlPush:String = new String();
	for (var n = 0; n<toXML.length; n++) {
		xmlPush += toXML[n];
	}
	return xmlPush;
}

```

These two functions create the xml fine, but I can’t refer to that xml anywhere outside of the xmlIt() function. It comes up as undefined in the trace.

How does one go about doing this?

Thanks!
