1. Saving foundation
There are some commands that Flash use in order to send data to the server. Sumarily:
| Class | Command | Example |
| getURL(), trough GET or POST methods | getURL("myScript.php", "_new", "POST") | |
| loadVariables, trough GET append some variable in the URL string | loadVariables("myScript.php?myVar=1") | |
| LoadVars | send() and senAndLoad() methods | myData.sendAndLoad("myScript.php", myData, "POST") |
| XML | send() and sendAndLoad() methods | myXml.sendAndLoad("myScript.php", someXML) |
| XMLSocket | send() and sendAndLoad() methods | myXmlSocket.send(myXml) |
Each of the methods are used for different scenarios. getURL will be useful only if we want send data and open a new page at same time. XML methods are suitable when using XML data. The XML socket is used in conjunction with socket servers. LoadVariables was the main method in Flash 5, but in newer versions, the Loadvars object is much better because encapsulation and callback handlers, so we will explain only this way of sending data.
Now let's move to the Flash side. We can send data trough GET or POST methods. Since GET is suitable for little packets (less than 255 characters), POST is better, since we don't have a length limit. Here's a summary example in how to send the content of a variable named title from Flash to some back-end script:
myData = new LoadVars()
myData.title = title
myData.sendAndLoad("message.php", myData, "POST")
myData.onLoad = function(ok){
if(ok){
trace ("Data saved")
}
}
So here we first instantiate a LoadVars object, then we use the sendAndLoad method to send the title variable to the back-end script and finally we use the onLoad to manage some answer of our script, usually an "ok" message if the data was successfully saved or an error message if not. This way of sending and loading content has two main features:
- Data is encapsulated, so we can manage which variables to send
- We can check the success of the process whit out the need of looping until
we receive an answer, since the onLoad handler takes care of this.
Examples
Use the examples files (download from main page) from the source in this tutorial to follow next chapters. Each method is inside his own folder (text, SharedObject, DB and Remoting)
Now move to our example using a text file.

5 most recent
Flash button as Flex icon
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles