XML.onData( ) Event Handler

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
XML.onData( ) Event Handler Flash 5

executed when external XML source code finishes loading but has not yet been parsed
xmlDoc.onData(src);

Arguments

src

A string containing the loaded XML source code.

Description

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.

Example

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");

See Also

XML.onLoad( ), XML.load( )



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net