
LoadVars.onData() Event Handler
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
583
Description
The loaded property provides a quick means of determining whether variables have finished
loading. For a new LoadVars object,
loaded is set to undefined. After the first call to load( )
or sendAndLoad( ),
loaded is set to false. If download never completes, due to an error or
poor connection, it remains
false. If download does complete, loaded is set to true by
loadVarsObject.onData( ) and remains true until the next call to load( ) or sendAndLoad( ).
In most cases, LoadVars.onLoad( ) provides the best way to respond when variable loading
completes. However, the
loaded property is handy when a separate segment of code needs
immediate access to the load status of a LoadVars object, as described in the following
Example.
Example
Consider a game that loads high scores and offers a button to email scores to a friend. The
button should work only if the scores are loaded, as follows:
// highScoreVars is assumed to be a global variable containing a LoadVars object
emailButton.onRelease = function () {
if (highScoreVars.loaded = = true) {
// Proceed with email code...
} else {
// Variables aren't loaded. Tell user to wait...
}
}
See Also
LoadVars.onLoad( )
LoadVars.onData() Event Handler
handler executed when external variable ...