Using LoadVars.send Method to Exchange Data with a Server-Side Script
Using LoadVars.send Method to Exchange Data
with a Server-Side Script
If you want to send variables from Flash to a server-side script (such as ColdFusion, PHP, ASP, etc.) you can use the LoadVars class’ send method. The code below creates a new LoadVars instance, adds a few values to the LoadVars object and then sends the variables to a script called inserthighscore.cfm as Form variables (using the POST method). If you wanted to send the variables as URL variables instead, you would need to simply change the POST to a GET. The one important thing about using LoadVars.send is that a new browser window is generally launched. If you don’t want a new browser window to necessarily open each time the person receives a high score, you may wan tto use the LoadVars class’ sendAndLoad method instead.
- var myLoadVars_lv:LoadVars = new LoadVars();
- // create some variables in the LoadVars instance.
- myLoadVars.timestamp = new Date();
- myLoadVars.name = name_txt.text;
- myLoadVars.score = score_txt.text;
- // send variables in the LoadVars object to the server-side script.
- /* Flash will send these variables to the specified page using the method, in this case POST, and launch a new window which will display the results. */
- myLoadVars.send(“inserthighscore.cfm”, “_blank”, “POST”);