Yes, oops. It was late (early). :)

David Skoglund wrote:
In the "not so clean version", I belive you would need to set the prop "ref" to this before loading.

Like this:

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.ref=this; <<<<<<<<<<<<<<<<<<<<<<<<<<
xmlData.onLoad = function(success:Boolean){
   ref.init(success,this);
}

/David

----- Original Message ----- From: "js" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Sunday, June 18, 2006 12:54 PM
Subject: Re: [Flashcoders] XML load within an object


import util.Proxy;

class Widget {

private var _someProperty:Number = 5;

public function Widget(xmlFile:String){

var xmlData:XML;

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = Proxy.create(this,init,xmlData);
xmlData.load(xmlFile);

}

private function init(success:Boolean, xmlData:XML){
trace(success);
trace(this._someProperty);
trace(xmlData);
}
}


You can get proxy from http://www.person13.com/articles/proxy/Proxy.htm

Alternatively (and not as cleanly):

class Widget {

private var _someProperty:Number = 5;

public function Widget(xmlFile:String){

var xmlData:XML;

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function(success:Boolean){
ref.init(success,this);
}
xmlData.load(xmlFile);

}

private function init(success:Boolean, xmlData:XML){
trace(success);
trace(this._someProperty);
trace(xmlData);
}
}


onLoad dosen't "take" parameters -- it's being invoked by the XML
class from a private method and passed a boolean value so that you can
evaluate if the load was successful.
With "= function(success:Boolean){...", you are assigning the onLoad
method an anonymous function so that when the method does eventually
get invoked after a successful load, your functionality is invoked as
well.

--

Joseph Sorensen


D_C wrote:
i have a UI widget that loads its own layout info from an XML file.

is there a way to set the xml.onLoad to a useful function?

I would like to have the xml.onLoad callback to initialize the object
itself, like this:

class MyWidget {
 function myWidget(xmlFile) { // constructor
           xmlData = new XML();
        xmlData.load( xmlFile );
        xmlData.onLoad = this.init(xmlData);  // doesnt work
 }
 function init(xmlData) {
   /// do layout stuff here
 }

}

it seems the xml.onLoad will only take a function with a single
boolean parameter? eg
 xmlData.onLoad = function(success)  {  // ...

is there another pattern for doing this?

thanks!

/dc
_______________________________________________
          David "DC" Collier

[EMAIL PROTECTED]
          skype: callto://d3ntaku
          http://www.pikkle.com
          +81 (0)80 6521 9559

http://charajam.com 【★キャラ♪ジャム★】
人気キャラとJ-POP最新ヒット曲を自分で組み合わせて
待受Flashや着Flashを作っちゃおう!
_______________________________________________
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



--
--

*Joseph Sorensen* / *Skyform* ©
Web Design / Audio Production / Photography
*Web:* aerosdesign.com/jsorensen
*Em:* jsorensen[at]aerosdesign.com
*Ph:* 815.276.9006
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com



--
--

*Joseph Sorensen* / *Skyform* ©
Web Design / Audio Production / Photography
*Web:* aerosdesign.com/jsorensen
*Em:* jsorensen[at]aerosdesign.com
*Ph:* 815.276.9006
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to