XMLParser in custom class?

XMLParser and XMLManager questions/comments/discussions

XMLParser in custom class?

Postby monteverest » Wed Jan 27, 2010 8:46 pm

Hi Jack,

Thanks for the XML parser - I'm very enthusiastic about using it in a current project in which I transfer text to a dignified XML. However, I ran into a problem and I suspect it's a scoping issue:

In my project, I have a custom class with a movieclip composite and when the onFinish function fires, everything works fine except the function will not call any function in the class. Here's a very simplified version of the code I'm working with:

import com.greensock.dataTransfer.XMLParser;
class WhoWeAre2 {

var parsedObject:Object;
var _this:MovieClip;
var _d:Number;

public function WhoWeAre2 (target:MovieClip, d:Number) {
XMLParser.load("_assets/whoWeAre.xml", onFinish, null, false, true);
}

public function onFinish($success:Boolean, $parsedObject:Object, $xml:XML):Void {
if ($success) {
trace("The first asset is: "+$parsedObject.copy[0].title[0].nodeValue);
traceIt();
} else {
trace("cannot load XML"); }}

private function traceIt():Void {
trace("hello");
}
}

thanks a million if you can help!!!
monteverest
 
Posts: 2
Joined: Wed Jan 27, 2010 8:36 pm

Re: XMLParser in custom class?

Postby greensock » Wed Jan 27, 2010 9:36 pm

Yep, that's one of the many things I don't miss about AS2 - scope issues. You can resolve it with the Delegate class:

Code: Select all
import mx.utils.Delegate;
XMLParser.load("_assets/whoWeAre.xml", Delegate.create(this, onFinish), null, false, true);
User avatar
greensock
Site Admin
 
Posts: 4718
Joined: Wed Jun 11, 2008 2:13 pm
Location: Chicago

Re: XMLParser in custom class?

Postby monteverest » Wed Jan 27, 2010 10:17 pm

A very belated thank you. I'll be joining Greensock at the conclusion of this project as the service you provide deserves tribute.
monteverest
 
Posts: 2
Joined: Wed Jan 27, 2010 8:36 pm


Return to XML