Look Ma! No Delegate....
///////////////////////////////
var scope = this;
var callback = "xml_parse";
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = xml_loaded;
xmlData.load ( "gallery.xml" );
function xml_loaded( success:Boolean )
{
if ( success ) scope [ callback ] ( this );
}
function xml_parse ( xml:XML )
{
var total = xml.firstChild.firstChild.childNodes.length;
trace ( this + " xml_loaded :: total: " + total );
}
///////////////////////////////
xmlData = new XML();
xmlData.scope = this;
xmlData.ignoreWhite = true;
xmlData.onLoad = function ( success:Boolean )
{
if ( success ) this.scope.xml_parse ( this );
}
xmlData.load ( "gallery.xml" );
function xml_parse ( xml:XML )
{
var total = xmlData.firstChild.firstChild.childNodes.length;
trace ( this + " xml_loaded :: total: " + total );
}
///////////////////////////////
Event Dispatcher
///////////////////////////////
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function ( success:Boolean )
{
this.dispatchEvent ( { target:this, type:"xml_onLoad",
success:success } )
}
mx.events.EventDispatcher.initialize ( xmlData );
xmlData.addEventListener ( "xml_onLoad", this );
xmlData.load ( "gallery.xml" );
function xml_onLoad ( evt:Object ) {
var xml = evt.target;
var total = xmlData.firstChild.firstChild.childNodes.length;
trace ( this + " xml_loaded :: total: " + total );
}
///////////////////////////////
Or, sorta Delegate style...
///////////////////////////////
function createAndLoadXML ( path:String, scope:Object, callback:Function )
{
var func = function ( success:Boolean )
{
this.onLoad = null; // clear some memory?
var scope = arguments.callee.scope;
var callback = arguments.callee.callback;
callback.call ( scope, this, success );
}
func.scope = scope;
func.callback = callback;
func.xml = new XML();
func.xml.ignoreWhite = true;
func.xml.onLoad = func;
func.xml.load ( path );
}
function xml_parse ( xml:XML, success:Boolean )
{
var total = xml.firstChild.firstChild.childNodes.length;
trace ( this + " xml_loaded :: total: " + total );
}
createAndLoadXML ( "gallery.xml", this, xml_parse );
_____________________________
Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_____________________________
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul Andrews
Sent: Sunday, July 08, 2007 12:22 PM
To: [email protected]
Subject: Re: [Flashcoders] XML loading and parsing problem
Best practice, fine. Only practice, no.
> regards,
> Muzak
Paul
_______________________________________________
[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