Flash is one of the very few technologies that enable the web to be responsive, interactive and interesting. However all the animation doesn’t mean much without some data. I love Flash, but when it comes to getting data in and out of Flash…it becomes not as easy as many of the other programming languages or broadband technologies. One of the ways (also probably the most common) to have Flash communicate is with the LoadVars.send or the LoadVars.sendAndLoad method.
Use LoadVars.send if you want to send data to a server-side script (Webservice, .NET, AMFPHP)
Use LoadVars.sendAndLoad if you want to send data to a server-side script and expect a response of some sort.
In a recent project for Bayer’s Aleve Web 2.0 adventure I used sendAndLoad to send data about the user (through a Flash cookie) to a webservice that tracked where the user went to. This was very useful information for finding out if we needed to change the design to help the user get through the site or if something was unclear, etc.
See Code Below
Below I have posted some code that can be used in any project that you need with some very small modifications.
CODE:
//Values Of Variables To Send
var user_id:Number;
var event_title:String = “”;//Create an object to handle the data loading
loadLV = new LoadVars();
loadLV.onLoad = function (success) {
if (success) {
trace(“loaded results”);
}
}//Create an object to send the variables to the script
sendLV = new LoadVars();//Define Variables To Send
//Change the names of the variables and add or subtract any variables you would like to send
sendLV.userID = user_id; //User ID Variable
sendLV.EventTitle = event_title; //Event Title Variable//Send Variables
//CHANGE “your_server_side_script_address_here” to the address of the server-side script that you want to send your variables to
sendLV.sendAndLoad(“your_server_side_script_address_here”, loadLV);
For more information on ways Flash can communicate check out:
- AMFPHP – turns your PHP into an easily accessible webservice. Works great with Flex. Can use JSON, XML, and if you get it configured just right can send arrays to Flash from PHP
- Flash talking to PHP, MySQL in a DataGrid Component Example
- Flash Remote Shared Objects Example – you need the Flash Communication server for this













Last
Youtube
Twitter
Digg
RSS