View comments | RSS feed

LoadVars


Object
    |
    +-LoadVars

public dynamic class LoadVars
extends Object

You can use the LoadVars class to obtain verification of successful data loading and to monitor download progress. The LoadVars class is an alternative to the loadVariables() function for transferring variables between a Flash application and a server.

The LoadVars class lets you send all the variables in an object to a specified URL and to load all the variables at a specified URL into an object. It also lets you send specific variables, rather than all variables, which can make your application more efficient. You can use the LoadVars.onLoad handler to ensure that your application runs when data is loaded, and not before.

The LoadVars class works much like the XML class; it uses the load(), send(), and sendAndLoad() methods to communicate with a server. The main difference between the LoadVars class and the XML class is that LoadVars transfers ActionScript name and value pairs, rather than an XML Document Object Model (DOM) tree stored in the XML object. The LoadVars class follows the same security restrictions as the XML class.

Availability: ActionScript 1.0; Flash Player 6

See also

loadVariables function, onLoad (LoadVars.onLoad handler), XML

Property summary

Modifiers

Property

Description

 

contentType:String

The MIME type that is sent to the server when you call LoadVars.send() or LoadVars.sendAndLoad().

 

loaded:Boolean

A Boolean value that indicates whether a load or sendAndLoad operation has completed, undefined by default.

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

onData = function(src:String) {}

Invoked when data has completely downloaded from the server or when an error occurs while data is downloading from a server.

onHTTPStatus = function(httpStatus:Number) {}

Invoked when Flash Player receives an HTTP status code from the server.

onLoad = function(success:Boolean) {}

Invoked when a LoadVars.load() or LoadVars.sendAndLoad() operation has ended.

Constructor summary

Signature

Description

LoadVars()

Creates a LoadVars object.

Method summary

Modifiers

Signature

Description

 

addRequestHeader(header:Object, headerValue:String) : Void

Adds or changes HTTP request headers (such as Content-Type or SOAPAction) sent with POST actions.

 

decode(queryString:String) : Void

Converts the variable string to properties of the specified LoadVars object.

 

getBytesLoaded() : Number

Returns the number of bytes downloaded by LoadVars.load() or LoadVars.sendAndLoad().

 

getBytesTotal() : Number

Returns the total number of bytes downloaded by LoadVars.load() or LoadVars.sendAndLoad().

 

load(url:String) : Boolean

Downloads variables from the specified URL, parses the variable data, and places the resulting variables in my_lv.

 

send(url:String, target:String, [method:String]) : Boolean

Sends the variables in the my_lv object to the specified URL.

 

sendAndLoad(url:String, target:Object, [method:String]) : Boolean

Posts variables in the my_lv object to the specified URL.

 

toString() : String

Returns a string containing all enumerable variables in my_lv, in the MIME content encoding application/x-www-form-urlencoded.

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


dubnet.co.uk said on Nov 4, 2005 at 8:29 AM :
I have created 2 LoadVars objects, each to store in /out going variables.

I am calling a coldfusion page but I am not able to get the variables back into Flash. What forma must the variables in coldfusion be? Not valued pairs as this doesnt work.

Please help?
|mantra| said on Jan 15, 2006 at 6:17 AM :
i'm not sure what you are doing on either side with your variables, however an example of how you can pass information you're returning to flash from a cfm file can be sent in a format like so:
&variable1=your data, &variable2=more data.

If you have your content already set in a coldfusion variable you can just do something similiar in your cfm file:
&variable1=<cfoutput>#cfmVariable1#</cfoutput>, &variable2=<cfoutput>#cfmVariable2#</cfoutput>.

Of course anything your passing back to flash needs to have an appropriate place to go to. such as dynamic textfield to output into or whatever else you are doing with it.

Hope this helps.
Mark
tb2000 said on Mar 13, 2006 at 7:51 AM :
LoadVars is appropriate for URL querystring data only. If you are trying to send or consume complex or specific datatypes (i.e. objects and associative arrays, integers, etc) you need to use remoting or web services.
Linto.K.A. said on Mar 28, 2006 at 8:04 AM :
Can I know what is the maximum size of the string that can be sent using LoadVars object .......???

When I tried to send one very big string , it shows this error message ....... " A script in this movie is causing Flash Player to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

Pls advice...

lintoka_123@yahoo.com, linto.ka@ascendum.com
F-r-e-y said on Apr 5, 2006 at 6:33 AM :
I have this code:
<i>
var nahratInfo2 = new LoadVars();
nahratInfo2.load("nastavenie.txt");
nahratInfo2.onLoad = function() {
info0 = nahratInfo2.info0.split(";");
info0 = info0[0];
red = nahratInfo2.red.split(";");
red = red[0];
green = nahratInfo2.green.split(";");
green = green[0];
blue = nahratInfo2.blue.split(";");
blue = blue[0];
};
</i>
When I compile a *.swf file, the variables have been loaded correctly. But if I compile a projector file (*.exe), there is no variables loaded. Can somebody help me with this? I am using Macromedia Flash Professional 8.0
Thanks.
gevert said on Aug 29, 2006 at 11:49 AM :
This does not reference the use of LoadVars to precache data in the browser as referenced in this article http://www.actionscript.com/Article/tabid/54/ArticleID/Preloading-Files-into-the-Browser-s-Cache/Default.aspx - I'm wondering if anyone has heard anything official from Adobe about support for this use of the API.
No screen name said on Sep 5, 2006 at 11:34 AM :
I am using LoadVars perfectly and it is working perfectly when I test it with ctrl-enter from flash professional 8 editor. When I compile the swf and upload it so it can be tested online it trips up when checking an exact value of a loaded string ( but it doesnt trip up when tested in developement using ctrl-enter ).

This is what goes wrong:
if (lVars.someVar == "thevalue"){

this will never return true even though when printed in the flash from a dynamic text field it displays exactly what is above ( "thevalue" ).

If I do this I get a value of greater than zero :
index = lVars.someVar.indexOf("evalu");
if( index > 0){

What is going on here? What magical function do I need to do to initialize the strings received from LoadVars so that they can be used to compare to an exact string value? I have tried the String and unescape commands with no luck. I can never check if a LoadVars.string is equal to "johnny" but I can see that a string contains the string "johnny" in it ...
wearHD.com said on Oct 6, 2006 at 2:53 PM :
Note that the LoadVars object CANNOT be used to send multidimensional data. So do NOT try to do the following:

/*********code************/
var myLv:LoadVars = new LoadVars();
myLv.item1 = name1;
myLv.item1.prop1 = value1;
myLv.item1.prop2 = value2;
myLv.item2 = name2;
myLv.item2.prop1 = valueA;
myLv.item2.prop2 = valueB;

myLv.sendandload("myScript", myLv, "POST");
/********** end code **************/

This will not output any errors anywhere, but will only post the item1, item2, data; the .prop1, .prop2 data will simply be dropped.

If you need to send nested data, send it like this:
myLv.item1_prop1 = value1;
myLv.item2_prop2 = value2;
etc. etc.

Hopefully this helps someone avoid lots of painful hours trying to figure out why their server script isn't working, when it was the LoadVars object in Flash not working all along!!
Stingwear said on Dec 21, 2006 at 8:48 AM :
I have a question for everyone.
Can I send variables with loadvars and get the response with a XML object?
I make this question because I've try it but it doesn't works.

Thanks

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002323.html