I have a class with a XML object in it. In one of the class’ methods, I tell the XML object to load a document. Before I do that, I set up the onLoad event to call one of the class’ other methods. The problem is that in that handler function, I can’t seem to access any of my class’ data. If I try to use the “this” pointer, I’m getting the XML object not my class.
A simple example:
[AS]
class MyClass
{
var theXML:XML;
var someVariable:Number;
function MyClass()
{
theXML = new XML();
theXML.onLoad = XMLLoadHandler;
theXML.load( “testFile.xml” );
}
function XMLLoadHandler(success)
{
// This function gets called when the XML is done parsing,
// but I can’t access any of the data or methods in this class!!
// What do I need to do?
trace(someVariable); // does not exist
}
}
[/AS]
For your class use this
[AS]
class MyClass extends XML
{
var theXML:XML;
var someVariable:Number;
function MyClass()
{
this.theXML = new XML();
this.theXML.onLoad = this.XMLLoadHandler();
this.theXML.load( "testFile.xml" );
}
function XMLLoadHandler(success)
{
// This function gets called when the XML is done parsing,
// but I can't access any of the data or methods in this class!!
// What do I need to do?
trace("this is to test my class"); // does not exist
}
}
[/AS]
Then on your main scene in a ‘actions’ layer…add this script to call the class.
[AS]
import myClass
_root.onLoad = function()
{
var myVar:MyClass = new MyClass();
trace(myVar.ignoreWhite); //These two lines of code are 2 show that you have inheritted the XML class properties
trace(myVar.firstChild); //And to show that you can set the properties outside your class
}
[/AS]
If I havn’t understood correctly, please explain again so I can help out.