Accessing xml date from subclass
I am building a app that pulls data from xml. The different nodes in the xml needs to build different objects. My thinking was that I must import the xml only once. Then build seperate classes for each object type. These classes will extends the xml class and apply whatever it needs to do with specific nodes data.
Problem is that it seems like the subclass is created before the xml loaded. I can trace the xml data from the xml superclass but not from the subclass.
Main Class
Actionscript Code:
package MyClasses
{
import flash.display.Sprite;
import MyClasses.Dateline;
public class Main extends Sprite
{
private var dateLine;
public function Main()
{
dateLine==new(Dateline);
}
}
}
Xml super class
Actionscript Code:
package MyClasses
{
import flash.display.*
import flash.display.Loader;
import flash.xml.*;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
//read xml
public class Xml
{
public var myXML:XML;
var xmlLoader:URLLoader = new URLLoader();
public function Xml()
{
xmlLoader.load(new URLRequest("../../assets/xml/data.xml"));
xmlLoader.addEventListener(Event.COMPLETE, processXML);
}
function processXML(e:Event):void
{
xmlLoader.removeEventListener(Event.COMPLETE, processXML);
myXML = new XML(e.target.data);
myXML.ignoreWhite = true;
trace(myXML)
}
}
}
subClass
Actionscript Code:
package MyClasses
{
//create dateline
import flash.display.MovieClip
import flash.display.Sprite;
import MyClasses.Xml;
public class Dateline extends Xml
{
public var dataHolder:String
public function Dateline()
{
trace(myXML)
}
}
}