# AS2.0: How to return an array from XML read class

**URL:** https://forum.kirupa.com/t/as2-0-how-to-return-an-array-from-xml-read-class/170352
**Category:** flash
**Created:** [November 24, 2005, 11:26pm UTC](https://forum.kirupa.com/t/as2-0-how-to-return-an-array-from-xml-read-class/170352 "2005-11-24T23:26:19Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Moga](https://avatars.discourse-cdn.com/v4/letter/m/45deac/32.png) [@Moga](https://forum.kirupa.com/u/Moga)
#### Post date: [November 24, 2005, 11:26pm UTC](https://forum.kirupa.com/t/as2-0-how-to-return-an-array-from-xml-read-class/170352/1 "2005-11-24T23:26:19Z")

</div>

Hope anyone can help me.  
I’m trying to write an external as2.0 class that will read an xml file and return an array that I can use in my project. I manage to read a normal xml file inside my flash project, but because I will need to use this function a lot of times I rather get this class to work 😉

The problem:  
I manage to get the reading to work, but to get actually read the data outside the onload function is the problem…and this is where I need it!

The code:

```auto
  
class ProjectImagesXML extends MovieClip {
 /*
 Properties:
 */
 var _imageArray:Array = new Array;
 /*
 Constructor:
 */
 function ProjectImagesXML() {
 }
 /*
 Methods
 */
 /*
 GetImages --> Read xml file and return Array with images
 @_nodeName: sent nodeName, check position in xml file and return childNode.nodeValues
 @_xmlUrl: url from xml to read
 */
 function GetImages(_nodeName:String, _xmlUrl:String):Array {
  var imageXML:XML = new XML();
  imageXML.ignoreWhite = true;
  imageXML.onLoad = function(success:Boolean) {
   if (success) {
	var _rootNode:XMLNode = this.firstChild.firstChild.firstChild;
	if (_rootNode.hasChildNodes()) {
	 // Iterate through the child nodes of rootNode
	 for (var aNode:XMLNode = _rootNode; aNode != null; aNode=aNode.nextSibling)
	 {
	  // check if current node is same as given parameter _nodeName
	  if (aNode.nodeName == _nodeName)
	  {
	   var bNode:XMLNode = aNode;
	   for (var cNode:XMLNode = bNode.firstChild; cNode != null; cNode = cNode.nextSibling)
	   {
		//trace(cNode.firstChild.nodeValue);
		_imageArray.push(cNode.firstChild.nodeValue);
		//trace(cNode.firstChild.nodeValue);
		trace(_imageArray); // this one gives undefined
		
		//But this does work though:
		/*
		new tempArray:Array = new Array();
		tempArray.push(cNode.firstChild.nodeValue);
		trace(tempArray);
		*/
		return _imageArray;
	   }
	  }
	 }
	}
   }
  };
  imageXML.load(_xmlUrl);
 }
}

```

I’ll have to put somewhere a this. or target I supose -read it ones in an article I can’t find anymore :\*( - Can anyone please help me out of this misery?

Moga
