1. Saving foundation
There are some commands that Flash use in order to send data to the server. Sumarily:
| Class | Command | Example |
| Flash.net package | flash.net.sendToURL(), flash.net.navigateToURL() method | sendToURL(new UrlRequest( "myScript.php")) |
| URLLoader | URLLoader.load() method plus URLRequest with data property | myLoader.load(new UrlRequest( "myScript.php")) |
| NetConnection | call() method | myNetConnection.call("News.insert", responder, vars) |
| Socket | read/write | mySocket.writeInt(6) |
Each of the methods are used for different scenarios. navigateToURL will be useful only if we want send data and open a new page at same time. The Socket is used to write low level data packets. The URLLoader is the main method to send any data (attached to the data property of a URLRequest instance), and we will explain only this way of sending data and Remoting.
Let's explain 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:
var myData:URLRequest = new URLRequest("some.php")
myData.method = URLRequestMethod.POST
var variables:URLVariables = new URLVariables()
variables.title = "Hi friends"
variables.nr = 5
myData.data = variables
var loader:URLLoader = new URLLoader()
loader.dataFormat = URLLoaderDataFormat.VARIABLES
loader.addEventListener(Event.COMPLETE, dataOnLoad)
loader.load(myData)
function dataOnLoad(evt:Event){
trace(loader.data.status) //status is a custom flag passed from back-end
}
So here we first instantiate a Loader object, then we use URLRequest object to send the title and nr variable to the back-end script and finally we add a listener to handle some answer of our script. Note that we use explicitely the POST method (GET by default) and set the loader dataFormat to variables because we expect URLEncoder data. To summarize things you should keep an eye on:
- The URLRequest should encapsulate all data to be sended inside a URLVariables object that will be the data property of the URLRequest object
- URLRequest method is GET by default (in the old LoadVars object the default method was POST), so you need to change if you want to use POST
- Downloaded data as name/value pairs is appended to the data property of the URLLoader
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 streaming servers
Tree menu
Flash Spell Checker
Flash Remoting Library
MX 2004 Chart/Poll
Articles