The LoadVars object offers a cleaner, easier way to carry out the task of exchanging data with a server. Adi Reddy Mora explains how this object, introduced in Flash Player 6, can help you to more easily transfer variables between a Flash movie and a server.
The Power of LoadVars Object - LoadVars.decode (Page 5 of 5 )
This method can be used to internally decode name/value pairs into object properties and values. It accepts one argument as a string that contains name/value pairs and the string will be converted into object properties and associated values.
Name/value pairs look like the following: myvariable=value&myothervariable=anothervalue
This hidden method will convert the above name/value pairs into two properties "myvariable" and "myothervariable." The values of these properties are the associated values in the name/value pair string, so the value of "myvariable" in the above string is "value" and the value of "myothervariable" in the above string is "anothervalue." Here's a little code example to show you what this method does:
// create a new instance of the LoadVars object vat lv:LoadVars = new LoadVars();
// call the method with name/value pair string lv.decode("name=Jhon&age=22");
// iterate over all the properties in the ‘lv’ object for(var i in lv){ //trace the property name and property value trace(i+":"+ lv [i]) }
The output of the above code will be:
name:Jhon age:22
Conclusion
The LoadVars Object is the powerful way to obtain simple communication with any server or fo loading data from text files. However, for complex data communication it is recommended to use WebService Connector component available in Flash MX 2004 Professional, or you can also use Flash Remoting MX for an effective and efficient method of communicatio. Flash Remoting MX uses Action Message Format (AMF), a binary message format designed for the ActionScript object model, which was modeled on the Simple Object Access Protocol (SOAP).AMF uses a packed format to relay information so the communication with the server will be efficient.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.