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:
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