1. General loading principles
Flash can load data as big pieces of string. a list of name/value pairs. What I mean? That data must be a named variable with some value, like this:
name=Jorge
Here I have a variable named "name" with a value "Jorge". But what happens if I need more info, perhaps last name and age? I can use a string like this:
name=Jorge&lastname=Solis&age=30
Now I have three variables, each one holding a different information. Note that I use the "&" sign to separate values. This way I can pass any quantity of data to Flash, each one in a name/value pair format. This info could be in any file as far as it can be loaded by our movie.
Now let's move to the Flash side There are a couple of ways of loading data,
basically loadVariables() and the LoadVars() object. Since the better approach
is to use the LoadVars object, because encapsulation and callback handlers,
we will explain only this way of loading data.
So, having name=Jorge in a text file named data.txt, I can use this:
myData = new LoadVars()
myData.load("data.txt")
myData.onLoad = function(succes){
if(succes){
name.text = this.name
} else trace ("Error loading data")
}
So here we first instantiate a LoadVars object, then we use the load method to load the content of the text file, and finally we use the onLoad handler that fires when the content is totally loaded, to assign it to a textfield. The succes parameter is a boolean value set to true if the data has successfully loaded, if not, we trace an error message to the output window. This way of loading data has two important features:
- Data is encapsulated, so it doesn't overwrite any other variable in our movie
- We don't need to loop until data finish to download, since the onLoad handler
take care of this.
We will follow this way of loading data in all our examples.
Examples
So we have seen how Flash reads name/value pairs and how to use a LoadVars object to load it. Use the examples files from the source in this tutorial to follow next chapters. Each method is inside his own folder (txt, XML, DB and remoting)
Now move to our example using a text file.

5 most recent
Flash streaming servers
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles