Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

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.

  1. var myLoadVars_lv:LoadVars = new LoadVars();
  2. // create some variables in the LoadVars instance.
  3. myLoadVars.timestamp = new Date();
  4. = name_txt.text;
  5. myLoadVars.score = score_txt.text;
  6. // send variables in the LoadVars object to the server-side script.
  7. /* 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. */
  8. myLoadVars.send(“inserthighscore.cfm”, “_blank”, “POST”);