Advertisement
Guest User

Untitled

a guest
Jan 14th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. Send a array from PHP to AS3?
  2. function login_check (e:MouseEvent):void {
  3.  
  4. /*
  5. check fields before sending request to php
  6. */
  7.  
  8. if (login_username.text == "" || login_password.text == "") {
  9.  
  10. /*
  11. if username or password fields are empty set error messages
  12. */
  13.  
  14. if (login_username.text == "") {
  15.  
  16. login_username.text = "Enter your username";
  17.  
  18. }
  19.  
  20. if (login_password.text == "") {
  21.  
  22. login_password.text = "Enter your password";
  23.  
  24. }
  25.  
  26. } else {
  27.  
  28. /*
  29. init function to process login
  30. */
  31.  
  32. login_process();
  33.  
  34. }
  35.  
  36. }
  37.  
  38. /*
  39. function to process our login
  40. */
  41.  
  42. function login_process ():void {
  43.  
  44. /*
  45. variables that we send to the php file
  46. */
  47.  
  48. var phpVars:URLVariables = new URLVariables();
  49.  
  50. /*
  51. we create a URLRequest variable. This gets the php file path.
  52. */
  53.  
  54. var phpFileRequest:URLRequest = new URLRequest("php/controlpanel.php");
  55.  
  56. /*
  57. this allows us to use the post function in php
  58. */
  59.  
  60. phpFileRequest.method = URLRequestMethod.POST;
  61.  
  62. /*
  63. attach the php variables to the URLRequest
  64. */
  65.  
  66. phpFileRequest.data = phpVars;
  67.  
  68. /*
  69. create a new loader to load and send our urlrequest
  70. */
  71.  
  72. var phpLoader:URLLoader = new URLLoader();
  73. phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
  74. phpLoader.addEventListener(Event.COMPLETE, login_result);
  75.  
  76. /*
  77. now lets create the variables to send to the php file
  78. */
  79.  
  80. phpVars.systemCall = "login_check";
  81. phpVars.login_username = login_username.text;
  82. phpVars.login_password = login_password.text;
  83.  
  84. /*
  85. this will start the communication between flash and php
  86. */
  87.  
  88. phpLoader.load(phpFileRequest);
  89.  
  90. }
  91.  
  92. /*
  93. function to show the result of the login
  94. */
  95.  
  96. function login_result (event:Event):void {
  97.  
  98. /*
  99.  
  100. this autosizes the text field
  101.  
  102. ***** You will need to import flash's text classes. You can do this by:
  103.  
  104. import flash.text.*;
  105.  
  106. */
  107.  
  108. login_result_text.autoSize = TextFieldAutoSize.LEFT;
  109.  
  110. /*
  111. this gets the output and displays it in the result text field
  112. */
  113.  
  114. if (event.target.data.login_result == "1") {
  115. login_result_text.text = "Login In...";
  116. this.gotoAndStop("login_loggedin");
  117. }else{
  118. login_result_text.text = "Username and password doesn't match.";
  119. }
  120.  
  121. }
  122.  
  123. print "login_registration_status=1";
  124.  
  125. <?php print 'arr=1,2,3&var1=123&var2=456'; ?>
  126.  
  127. var data:Array = arr.split(',');
  128.  
  129. echo http_build_query(array(
  130. 'key1' => 'value1',
  131. 'key2' => 'value2',
  132. 'key3' => 'value3'));
  133.  
  134. var arrayToSend:Array = [ 'abc', 'def', [1, 2, 3] ];
  135.  
  136. var JSONArrayToSend:String = JSON.stringify ( arrayToSend );
  137. var arrayReceived:Array = JSON.parse ( JSONArrayReceived );
  138.  
  139. $JSONArrayToSend = json_encode( $arrayToSend );
  140. $arrayReceived = json_decode( $JSONArrayReceived );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement