
LoadVars.loaded Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
582
|
ActionScript Language Reference
Usage
In practice, the load( ) and sendAndLoad( ) methods may not trigger a download if the vari-
ables at
url are cached by the browser hosting the Flash movie. To force the browser to
always download variables (and bypass its cache) we can use a query string with a dummy
variable that contains a unique value. By convention, the current time in milliseconds is
used, as it is assumed to be sufficiently unique. For example:
theVars = new LoadVars();
theVars.load("http://www.site.com/vars.txt?cacheKiller=" + new Date().getTime());
The same effect can be achieved using the sendAndLoad( ) method to invoke an HTTP GET
request with a dummy variable (
cacheKiller):
varSender = new LoadVars();
varReceiver = new LoadVars();
varSender.cacheKiller = new Date().getTime();
varSender.sendAndLoad("http://www.yourserver.com/vars.txt", varReceiver, "GET");
In all cases, data should be verified inside the onLoad( ) handler before being used, because
cached data can be corrupt or incomplete. See LoadVars.onLoad( ) for an example.
Example
The following code uses a LoadVars object to retrieve the variable in the text file vars.txt,
which looks like this:
msg1=hello+world
Two variations of load( ) are shown, one with a unique cache-prevention variable: ...