We Recommend

HTML Dog: The Best-Practice Guide to XHTML and CSS HTML Dog: The Best-Practice Guide to XHTML and CSS
For readers who want to design Web pages that load quickly, are easy to update, accessible to all, work on all browsers and can be quickly adapted to different media, this comprehensive guide represents the best way to go about it.


Posted By

chrisaiv on 04/18/08


Tagged

as2


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

ninedaysoff


AS2: Simple Send and Load


Published in: ActionScript 


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


  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 = "blah@blah.com";
  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 

You need to login to post a comment.