XML.onData( ) Event Handler | Flash 5 |
executed when external XML source code finishes loading but has not yet been parsed |
A string containing the loaded XML source code.
The onData( ) handler executes automatically whenever raw XML source has finished loading into xmlDoc due to an earlier load( ) or sendAndLoad( ) invocation. The specified xmlDoc must be the top-level node in an XML object hierarchy (i.e., an instance of the XML class, not the XMLnode class).
By default, onData( ) has the following behavior:
If the raw source received is undefined, it calls xmlDoc.onLoad( ) with the success parameter set to false.
Otherwise, it parses the source into xmlDoc, sets xmlDoc.loaded to true, and calls xmlDoc.onLoad( ) with the success parameter set to true.
The onData( ) handler can be assigned a custom callback function to intercept raw XML source code before ActionScript has a chance to parse it. Under certain circumstances, manipulating raw XML source manually may offer improved performance over ActionScript's built-in parsing, particularly in Flash Player 5. In Flash Player 6, the native XML parsing usually is faster than custom ActionScript routines.
The following example shows how to display raw loaded XML source while preventing it from being parsed by ActionScript:
myDoc = new XML(); myDoc.onData = function (src) { trace("Here's the source: \n" + src); }; myDoc.load("book.xml");
The following example intercepts and displays raw loaded XML source, but it also performs onData( )'s normal duties:
myDoc = new XML(); myDoc.onData = function (src) { trace("Here's the source: \n" + src); if (src = = undefined) { this.onLoad(false); } else { this.parseXML(src); this.loaded = true; this.onLoad(true); } }; myDoc.onLoad = function (success) { trace("Here's the parsed XML: " + this); trace("Load succeeded? " + success); }; myDoc.load("book.xml");