Hi,
I am new to trying to put things into classes and am having trouble at a kind of basic level:
I have a class that will read an xml file and then load the xml into a public variable like this:
package
{
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.display.Sprite;
public class LoadXML extends Sprite
{
public var myXml:XML;
private var urlLoader:URLLoader=new URLLoader();
private var myUrl:String;
public function LoadXML(url:String)
{
myUrl = url;
init();
}
private function init():void
{
urlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
urlLoader.load(new URLRequest(myUrl));
}
private function onXMLLoaded(e:Event):void
{
myXml = new XML(e.target.data);
}
}
}
when I create an instance of this class from within another class like this:
xmlLoad:LoadXML = new LoadXML("test.xml");
the xml loads and I can trace it out from within the LoadXML class but when I try to access it from the class where I created the instance like this:
trace(xmlLoad.myXml);
it just returns “null”.
I’d appreciate any help - thanks!