LoadVars.onData( ) Event Handler

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

handler executed when external variable data finishes loading, but before it is parsed
loadVarsObject.onData(src);

Arguments

src

A string containing raw URL-encoded variables.

Description

The onData( ) handler executes automatically when raw variables requested by load( ) or sendAndLoad( ) have finished downloading but have not yet been parsed.

The onData( ) handler can be assigned a custom callback function to intercept raw variable source before ActionScript has a chance to convert the URL-encoded variables to loadVarObject properties and before onLoad( ) is called. This unmediated access to data loaded from the server can be useful for debugging. However, in most other cases a custom callback for onData( ) is not required.

By default (unless you define a custom callback function), onData( ) has the following behavior:

  • If the raw source received is undefined, it calls loadVarsObject.onLoad( ) with the success parameter set to false.

  • Otherwise, it uses loadVarsObject.decode( ) to convert the variables in src to properties of loadVarsObject, then sets loadVarsObject.loaded to true, and calls loadVarsObject.onLoad( ) with the success parameter set to true.

When implementing onData( ), be sure to convert the loaded variables to properties via decode( ), as shown in the following Example.

Example

The following example shows how to display raw loaded-variable source while preventing it from being parsed by ActionScript. The onLoad( ) method is not called, and the loaded property is not set:

loadedVars = new LoadVars(); loadedVars.onData = function (src) {   trace("Variables received: " + src); }; loadedVars.load("http://www.thesite.com/cgi-bin/getData.pl");

Here we display raw loaded-variable source but call onLoad( ) as it normally would be. Note that we take care to recreate all the default onData( ) behavior, including converting the loaded variables to properties with decode( ) and setting the loaded property to true:

loadedVars = new LoadVars(); loadedVars.onData = function (src) {   trace("Variables received: " + src);   if (src =  = undefined) {     this.onLoad(false);   } else {     this.decode(src);     this.loaded = true;     this.onLoad(true);   } };     loadedVars.onLoad = function (success) {   trace("Vars load successfully? " + success); }     loadedVars.load("http://www.thesite.com/cgi-bin/getData.pl");

See Also

LoadVars.decode( ), LoadVars.onLoad( )



    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