AS2: Simple Send and Load


/ Published in: ActionScript
Save to your folder(s)

This is pretty handy if you need to make a request to a server and receive a response. For example, you want to send an e-mail in Flash using some PHP script. On the PHP side, request will be sent as


Copy this code and paste it in your HTML
  1. var emailServer:String = "http://server.com/email.php"
  2.  
  3. var request:LoadVars = new LoadVars();
  4. var response:LoadVars = new LoadVars();
  5. response.onLoad = showResult;
  6.  
  7. /************************
  8. Server Request
  9. ************************/
  10. function sendEmail():Void{
  11. request.name = "chrisaiv";
  12. request.email = "[email protected]";
  13. request.url = "http://sendtoafriend";
  14. request.sendAndLoad(emailServer + "?clearCache=" + new Date().getTime(), response, "GET");
  15.  
  16. //Show data sent
  17. for (var prop in request){
  18. //trace( request[prop] + newline);
  19. }
  20. }
  21.  
  22. /************************
  23. Server Response
  24. ************************/
  25. function showResult():Void{
  26. if (this.success) {
  27. trace("File path: " + this.success);
  28. }
  29. }
  30.  
  31. sendEmail();

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.