PDA

View Full Version : XML parser in component


ajclarkson
09-01-2004, 03:51 PM
I am trying to author a flash component (v2) that will, among other things, load and parse an XML document.

My problem is that the XML.onLoad event seems to be out of scope to the rest of the class. Here's a concise version of my code:

class Foo extends UIComponent {

//member declarations
public var file_xml:XML;
public var some_arr:Array = new Array(); //repository for xml data

//constructor
function Foo (){};

private function init():Void {
super.init();
}

private function createChildren(): Void {
file_xml = new XML();
file_xml.onLoad = parseXML;
file_xml.load("file.xml");
}

public function parseIt(success:Boolean): Void {
trace(success); //outputs "true"
trace(this); //outputs entire XML document
trace(this.firstChild.nodeName); //generates compile error: "There is no property with the name 'firstChild' "
trace(file_xml); //outputs "undefined"
}
}//end class

When I drop an instance of the component in an fla and run it through the debugger, I can see the file_xml object in the inspector, and all its members (status, firstChild, etc.)

My ultimate objective is to parse the xml into objects and push them into some_arr.

Anyone know what's going on here?

Hobo

ajclarkson
09-01-2004, 10:25 PM
from the Blessed Grant Skinner, by way of Keith Peters:

http://www.gskinner.com/blog/archives/000070.html