XmlLoad
Kind of class: | class |
---|---|
Inherits from: | DataLoad < BytesLoad < RetryableLoad < Load < EventDispatcher < CoreObject |
Version: | 04/10/08 |
Author: | Aaron Clinger |
Classpath: | org.casalib.load.data.xml.XmlLoad |
File last modified: | Thursday, 26 March 2009, 09:22:13 |
Creates an easy way to load or send and load XML.
Since:
- Flash Player 7
Example:
- To load data:
function onXmlLoad(sender:XmlLoad):Void { trace(this.myXmlLoad.getXml().firstChild); } var myXmlLoad:XmlLoad = new XmlLoad("http://example.com/data.xml"); myXmlLoad.addEventObserver(this, XmlLoad.EVENT_LOAD_COMPLETE, "onXmlLoad"); myXmlLoad.start();
To send and load data:
function onXmlLoad(sender:XmlLoad):Void { trace(this.myXmlLoad.getXml().firstChild); } var myXmlSend:CoreXml = new CoreXml("<login><info user=\"CASA\" password=\"fr@m3w0rk\" /></login>"); var myXmlLoad:XmlLoad = new XmlLoad("http://example.com/login.php"); myXmlLoad.addEventObserver(this, XmlLoad.EVENT_LOAD_COMPLETE, "onXmlLoad"); myXmlLoad.setXml(this.myXmlSend); myXmlLoad.start();
To extend the XmlLoad class to parse and send"onParsed"
event:
import org.casalib.load.data.xml.XmlLoad; import org.casalib.xml.CoreXml; class com.package.MyClass extends XmlLoad { public function MyClass(xmlPath:String) { super(xmlPath); } public function parse():Void { var myXml:CoreXml = this.getXml(); for (var i:String in myXml.firstChild.childNodes) { // etc... } this.$parsed(); // Dispataches "onParsed" event } }
Usage note:
- Class must be extended to trigger/send
"onParsed"
event.
See also:
Events broadcasted to listeners:
onParsing = function (sender_xml:XmlLoad) {}
onParseError = function (sender_xml:XmlLoad, errorStatus:Number) {}
onParsed = function (sender_xml:XmlLoad) {}
Summary
Constructor
- XmlLoad (xmlPath:String)
- Defines file and location of load triggered by start.
Class properties
- EVENT_PARSING : String
- EVENT_PARSE_ERROR : String
- EVENT_PARSED : String
Class properties inherited from DataLoad
Class properties inherited from BytesLoad
Class properties inherited from RetryableLoad
Class properties inherited from Load
Instance methods
- setXml (xml:CoreXml) : Void
- Sets XML to be sent to the server along with the XML request.
- getXml : CoreXml
- Gets the XML object defined by the loaded XML, if loaded; or the the XML object defined by setXml, if not loaded.
- parse : Void
- This function needs to be overwritten by a subclass.
- destroy : Void
Instance methods inherited from DataLoad
Instance methods inherited from BytesLoad
Instance methods inherited from RetryableLoad
Instance methods inherited from Load
Instance methods inherited from EventDispatcher
Instance methods inherited from CoreObject
Constructor
XmlLoad
function XmlLoad (
xmlPath:String)
Defines file and location of load triggered by start.
Parameters:
path:
The absolute or relative URL of the XML to be loaded.
Class properties
EVENT_PARSE_ERROR
static EVENT_PARSE_ERROR:String = 'onParseError'
(read,write)
EVENT_PARSED
static EVENT_PARSED:String = 'onParsed'
(read,write)
EVENT_PARSING
static EVENT_PARSING:String = 'onParsing'
(read,write)
Instance methods
getXml
Gets the XML object defined by the loaded XML, if loaded; or the the XML object defined by setXml, if not loaded.
Returns:
- Returns the XML object.
parse
function parse (
) : Void
This function needs to be overwritten by a subclass.
Usage note:
- After the subclass file is done parsing call
private function $parsed()
in order to broadcast the 'onParsed' event to listeners.
setXml
Sets XML to be sent to the server along with the XML request.
Parameters:
xml:
The XML object to send.