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:
Instantiate a LoadVars object. Use load method to load the text file data into LoadVars object. Use onLoad event handler method to assign a function which fires when the variables are received from the text file. 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.
Please enable JavaScript to view the comments powered by Disqus. blog comments powered by