/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // A class to deal with the XML aspects of AS // that the Query class can access. //-------------------------------------------- class FA.build.xml_fns extends FA.Query { //-------------------------------------------- // This is a two purpose function. The first purpose // is as an event handler for the onLoad event. In that // case a function is passed to it. The second purpose // is to trigger the onLoad event by passing a url / filename // (a string) to the XML.load function. (assuming we're // using XML) //-------------------------------------------- public function load (event_or_url, event_fail:Function) : FA.Query { //-------------------------------------------- // do this so that if we want to, we can use $.load() // and it will work with the XML class. //-------------------------------------------- if (_is_dirty) { _object = new XML(); } //-------------------------------------------- // Work with the XML classes. //-------------------------------------------- if (_object instanceof XML or _object instanceof XMLSocket) { if (event_or_url.constructor == Function) { _object.onLoad = function(success:Boolean) : Void { if (success) { event_or_url.apply(this,[success]); } else { if(event_fail) { event_fail.apply(this,[false]); } } }; } else { _object.load(event_or_url); } } //-------------------------------------------- // Work with everything else.. e.g.: MovieClips //-------------------------------------------- else { _object.onLoad = function() : Void { event_or_url.apply(this,[success]); }; } return this; } //-------------------------------------------- // An event handler for the onData event. The // parameter passed is the function that will be // called when data is received. //-------------------------------------------- public function data (event_handler:Function) : FA.Query { if (_object.onData != undefined) { if (_object instanceof XML or _object instanceof XMLSocket) { _object.onData = event_handler; } } return this; } //-------------------------------------------- // An event handler for the onXML event. The // parameter passed is the function that will be // called when XML has been recieved or parsed // or whatever. :P //-------------------------------------------- public function xml (event_handler:Function) : FA.Query { if (_object instanceof XML or _object instanceof XMLSocket) { if (_object instanceof XMLSocket) { _object.onXML = event_handler; } } return this; } //-------------------------------------------- // Get or set a XML node attribute. //-------------------------------------------- public function attrib (attrib_key:String, attrib_value) { var ret = this; if (_object.attributes) { if (attrib_value != undefined) { _object.attributes[attrib_key] = attrib_value; } else { ret = _object.attributes[attrib_key]; } } else { } return ret; } //-------------------------------------------- // Close the connection with a socket. //-------------------------------------------- public function close () : FA.Query { if (_object instanceof XMLSocket) { _object.close(); } return this; } }