hide side navigation
    5 most recent
    Web Services
    Library's
    Component's
    Applications
    Articles
  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
  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.

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