Home arrow Flash arrow Page 4 - The Power of LoadVars Object
FLASH

The Power of LoadVars Object


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.

Author Info:
By: Adi Reddy Mora
Rating: 4 stars4 stars4 stars4 stars4 stars / 31
February 09, 2005
TABLE OF CONTENTS:
  1. · The Power of LoadVars Object
  2. · Advantages of the LoadVars class
  3. · Receiving the variables in server-side script
  4. · Using LoadVars Object for loading data from text files
  5. · LoadVars.decode

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
The Power of LoadVars Object - Using LoadVars Object for loading data from text files
(Page 4 of 5 )

LoadVars Object can also be used to load data from text files.

The following are the four basic steps involved in using LoadVars Object for loading text from .txt files into flash:

  1. Instantiate a LoadVars object.

  2. Use load method to load the text file data into LoadVars object.

  3. Use onLoad event handler method to assign a function which fires when the variables are received from the text file.

  4. Create a function with the name specified in step 3 to handle the received variables

Let us see an example now to demonstrate the above steps in ActionScript 2.0

Step 1

var load_lv = new LoadVars();

Step 2

load_lv.load("textfile.txt");

Step 3

load_lv.onLoad = loadTextVariables;

Step 4

function loadTextVariables(success){

if(success){
                   trace(this.name);

}
}

 

The text file should contain the data in the following format:

&name=John&id=342&ecode=e123

 

The following tables list all methods, properties and events of the LoadVars Object.

Methods:

Method

Description

LoadVars.load

Downloads variables from a specified URL.

LoadVars.getBytesTotal

Returns the number of bytes loaded from a load or sendAndLoad method.

LoadVars.getBytesTotal

Returns the total number of bytes that will be downloaded by a load or sendAndLoad method.

LoadVars.send

Posts variables from a LoadVars object to a URL.

LoadVars.sendAndLoad

Posts variables from a LoadVars object to a URL and downloads the server's response to a target object.

LoadVars.toString

Returns a URL encoded string that contains all the enumerable variables in the LoadVars object.

 
Properties:

Property

Description

LoadVars.contentType

Indicates the MIME type of the data.

LoadVars.load

A Boolean value that indicates whether a load or sendAndLoad operation has completed.


Event:

Event

Description

LoadVars.onLoad

Invoked when a load or sendAndLoad operation has completed.

 

There is a hidden method available in LoadVars class which was not documented in flash documentation.


blog comments powered by Disqus
FLASH ARTICLES

- More Top Flash Game Tutorials
- Top Flash Game Tutorials
- Best Flash Photo Gallery Tutorials
- The Top Flash Tutorials for Menus
- 7 Great Flash Tutorials
- Adobe Creative Suite 5.5 Now Available
- Critical Flash Vulnerability Heats Up the Web
- More on Nonpersistent Client-Side Remote Sha...
- Nonpersistent Client-Side Remote Shared Obje...
- Using the Decorator Pattern for a Real Web S...
- Using Concrete Decorator Classes
- Delving More Deeply into the Decorator Patte...
- The Decorator Pattern in Action
- A Simple Decorator Pattern Example
- Decorator Pattern

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials