New to AS3 and returning to OOP and very confused:
I’m trying to write and use a class to just load any xml data and pass that data back to any calling client code.
The class to load the xml works fine as far as loading the xml, but I’m confused about how to use the class, ie, how to call the xml data in the client code. Here’s the class to load the xml:
package com.xml{
import flash.net.*;
import flash.events.Event;
public class XmlLoader{
private var path:String = new String();
private var xmlLoader:URLLoader = new URLLoader();
private var xmlData:XML = new XML();
public function XmlLoader(xmlFilePath:String) {
this.path = xmlFilePath;
this.xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
this.xmlLoader.load(new URLRequest(this.path));
}
private function LoadXML(e:Event) {
this.xmlData = new XML(e.target.data);
}
public function getXML():XML {
return this.xmlData;
}
}
}
Here’s an example of a class in which I’m tyring to use the XmlLoader class:
package com.menu{
import flash.display.*;
import flash.net.*;
import flash.events.Event;
import com.xml.XmlLoader;
public class XmlMenu {
private var path:String;
private var loadedXML;
private var xmlData:XML;
public function XmlMenu(xmlFilePath:String = "menu.xml") {
this.path = xmlFilePath;
loadedXML = new XmlLoader(path);
this.xmlData = loadedXML.getXML();
trace(this.xmlData);
}
}
}
I’m instantiating the XmlMenu class on the root timeline of an .fla file like so:
import com.menu.XmlMenu;
var menu:XmlMenu = new XmlMenu();
At present, the trace() function in the above XmlMenu class returns empty. Previously I was getting an error: **Type Coercion failed: cannot convert MC to XML. **But now the trace() just returns blank…
Very confused…
Any advice? Thanks!