# XML.onLoad event handling \[MX2004\]

**URL:** https://forum.kirupa.com/t/xml-onload-event-handling-mx2004/42078
**Category:** flash
**Created:** [February 4, 2004, 10:35pm UTC](https://forum.kirupa.com/t/xml-onload-event-handling-mx2004/42078 "2004-02-04T22:35:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jasonp](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@jasonp](https://forum.kirupa.com/u/jasonp)
#### Post date: [February 4, 2004, 10:35pm UTC](https://forum.kirupa.com/t/xml-onload-event-handling-mx2004/42078/1 "2004-02-04T22:35:34Z")

</div>

Hi. I appreciate the help!

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]

Thanks!!

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 5, 2004, 4:34am UTC](https://forum.kirupa.com/t/xml-onload-event-handling-mx2004/42078/2 "2004-02-05T04:34:40Z")

</div>

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.

Cheers

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [February 6, 2004, 9:05pm UTC](https://forum.kirupa.com/t/xml-onload-event-handling-mx2004/42078/3 "2004-02-06T21:05:57Z")

</div>

Thanks for your help! I appreciate it.

Jason
