hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  Flash streaming servers  Flash button as Flex icon  Flex form by email  Hello Remoting with AS3  AS3 Saving data from Flash  AS3 Loading data into Flash  Fire Effect  Contact form  Dragable buttons  Hello World with openamf  Loading helper classes  Upload with Flash 8  Transitions effects  Snapshot with Flash 8  Hello World Remoting AS2  Flash AS2 Remoting Connector  Saving data from Flash  Loading data into Flash  FlashCom & Remoting login  Cell Renderer API  Editing a table using remoting components  Flash MX2004 web service classes  Browsing a catalog  amfphp Documentation  Hello World Remoting  Online Store with AMFPHP  Flash clients for Web Services  Web Service Walk Though with NuSoap  Popup windows in flash with javascript  Installing Apache/PHP  MoreOver News Feeds  Load Edit Save Text Files via CGI  Save Movie Clip Postion via PHP and MySQL
Current Page (1) Next Page >>  View Article Example >> 1 | 2 | 3 | 4 | 5 | 6 | 7
Untitled Document

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.COMPLETEdataOnLoad)
    
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.

Current Page (1) Next Page >> 1 | 2 | 3 | 4 | 5 | 6 | 7