AS2 LoadVars PHP example


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



Copy this code and paste it in your HTML
  1. /* LoadVars load example */
  2. // init LoadVars Object
  3. lv = new LoadVars();
  4.  
  5. // define onLoad Callback
  6. lv.onLoad = onLoadCallBack;
  7.  
  8. // send and load variables
  9. lv.load("http://localhost:2400/lv.txt?" + new Date());
  10.  
  11. // onLoad Callback
  12. function onLoadCallBack(succes)
  13. {
  14. // if succes
  15. if(succes)
  16. {
  17. // trace variables
  18. trace(this.lVar1);
  19. trace(this.lVar2);
  20. }
  21. else
  22. {
  23. // loading failed
  24. trace("Loading Error!!");
  25. }
  26. }
  27.  
  28. /*LoadVars send example*/
  29. // init LoadVars Object
  30. lv = new LoadVars();
  31.  
  32. // set Variables
  33. lv.sVar1 = "value1";
  34. lv.sVar2 = "value2";
  35.  
  36. // define onLoad Callback
  37. lv.onLoad = onLoadCallBack;
  38.  
  39. // send and load variables
  40. lv.sendAndLoad("http://localhost:2400/lv.php?" + new Date(), lv, "POST");
  41.  
  42. // onLoad Callback
  43. function onLoadCallBack(succes)
  44. {
  45. // if succes
  46. if(succes)
  47. {
  48. // trace variables
  49. trace(this.lVar1);
  50. trace(this.lVar2);
  51. }
  52. else
  53. {
  54. // loading failed
  55. trace("Loading Error!!");
  56. }
  57. }
  58.  
  59. /* PHP code */
  60. <?
  61. // get variables
  62. $var1 = $_POST['sVar1'];
  63. $var2 = $_POST['sVar2'];
  64.  
  65. // send variables
  66. echo "&lVar1=$var1 returned&";
  67. echo "&lVar2=$var2 returned as well&";
  68. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.