Hi.
Everything I need is find some nodeValue in xml file like this:
<school name="13">
<place name="facade">1.jpg</place>
<place name="entrance">2.jpg</place>
<school>
I wrote an abstract xml class which loads file:
class ruhe.util.AbstractXML extends XML
{
private var link:String;
private var event:String = "onXMLLoad";
private var errorEvent:String = "onXMLLoadError";
var dispatchEvent:Function;
var addEventListener:Function;
public function AbstractXML(xml_url : String)
{
super();
EventDispatcher.initialize(this);
ignoreWhite = true;
link = xml_url;
this.load(link);
}
private function onLoad(success:Boolean):Void
{
if(success)
{
this.dispatchEvent({type: event});
}
else
{
this.dispatchEvent({type: errorEvent});
}
}
}
and xml handler class:
class ruhe.school.XmlHandler {
private var info : AbstractXML;
private var hash : Object;
public function XmlHandler()
{
info = new AbstractXML("tree.xml");
info.addEventListener("onXMLLoad", Proxy.create(this, processXML));
info.addEventListener("onXMLLoadError", Proxy.create(this, raiseError));
}
private function raiseError() : Void
{
throw new Error("no xml found");
}
private function processXML() : Void{}
public function find(lookFor : String) : String
{
for (var n : Number = 0; n < info.firstChild.childNodes.length; n++)
{
if(info.firstChild.childNodes[n].attributes.name == lookFor)
{
return info.firstChild.childNodes[n].firstChild.nodeValue;
}
}
}
}
**find **method doesn’t work. it returns undefined. But when I change it to private and call from the **processXML **method everything works well.
private function processXML() : Void
{
trace (this.find("entrance")); *==> 2.jpg*
}
private function find(lookFor : String) : String
{
for (var n : Number = 0; n < info.firstChild.childNodes.length; n++)
{
if(info.firstChild.childNodes[n].attributes.name == lookFor)
{
return info.firstChild.childNodes[n].firstChild.nodeValue;
}
}
}
I thinck there is a stupid mistake somewhere in my code. I need public function find, not private.