class Async { static function loadXMLDocument(sourceURL:String):Deferred { var d:Deferred = new Deferred(); var myXML:XML = new XML(); myXML.onLoad = function(p_success:Boolean):Void { if (p_success) { myXML.attributes["sourceURL"] = sourceURL; d.callback(myXML); } else { d.errback(new Error("XML at " + sourceURL + " did not load")) } } myXML.load(sourceURL); return d; } }