• Domingo 22 de Diciembre de 2024, 05:59

Autor Tema:  problema AS Y PHP  (Leído 1260 veces)

thebcn

  • Nuevo Miembro
  • *
  • Mensajes: 1
    • Ver Perfil
problema AS Y PHP
« en: Domingo 26 de Octubre de 2008, 02:16 »
0
Hola Buenas noches
necesito ayuda con flash y actionscript, y php
uso smart fox server para hacer un juego multiplayer,

el problema es que el script del php era para recojer los usuarios que estaban en un array y decia que la base de datos la tenias que hacer tu y cambiar el script

el codigo de flash es
Código: Text
  1. import it.gotoandplay.smartfoxserver.*
  2.  
  3. stop()
  4.  
  5.  
  6.  
  7. //----------------------------------------------------------
  8. // Setup global variables
  9. //----------------------------------------------------------
  10. var stageW:Number = 700
  11. var stageH:Number = 490
  12.  
  13. // hide semi-transparent panel
  14. // used when a dialog box is shown
  15. disabler._visible = false
  16.  
  17. // isBusy is true when the application
  18. // is requiring input through a dialog box
  19. // When true all other controls are temporarily disabled
  20. _global.isBusy = false
  21.  
  22. // An event queue
  23. var evtQueue:Array = []
  24.  
  25.  
  26. //----------------------------------------------------------
  27. // Setup global variables
  28. //----------------------------------------------------------
  29. showLogin(false)
  30. status_txt.text = "Connecting..."
  31.  
  32.  
  33. //----------------------------------------------------------
  34. var ip:String       = "ipserver"
  35. var port:Number     = 9339
  36. var zone:String     = "simpleChat"
  37.  
  38.  
  39. //------------------------------------------------------------------
  40. // NOTE:
  41. // Change this url to your local or online webserver and poin it to
  42. // the webpage that verifies the login and password.
  43. // You will receive 2 POST variables called "login" and "pass"
  44. //
  45. // The server should respond with a "res" variable:
  46. // res=OK (if the user was recognized)
  47. // res=KO (if login failed)
  48. //------------------------------------------------------------------
  49. var serverPage:String   = "login.php"
  50. var serverIn:LoadVars   = new LoadVars()
  51. var serverOut:LoadVars  = new LoadVars()
  52.  
  53.  
  54. var smartfox:SmartFoxClient = new SmartFoxClient()
  55. smartfox.debug = true
  56.  
  57. smartfox.onConnection = handleConnection
  58. smartfox.connect(ip, port)
  59.  
  60.  
  61. //----------------------------------------------------------
  62. // Handle connection response from server
  63. //----------------------------------------------------------
  64. function handleConnection(success)
  65. {
  66.     if (success)
  67.     {
  68.         status_txt.text = "Connected, please login:"
  69.         showLogin(true)
  70.         butt_login.onRelease = validateLogin
  71.     }
  72.     else
  73.     {
  74.         status_txt.text = "Can't connect!"
  75.     }
  76. }
  77.  
  78. //----------------------------------------------------------
  79. // Send login data to the server page
  80. //----------------------------------------------------------
  81. function validateLogin()
  82. {
  83.     if (login_txt.text.length > 0 && pwd_txt.text.length > 0)
  84.     {
  85.         serverOut.name = login_txt.text
  86.         serverOut.pass = pwd_txt.text
  87.         serverOut.sendAndLoad(serverPage, serverIn, "post")
  88.     }
  89. }
  90.  
  91.  
  92.  
  93. //----------------------------------------------------------
  94. // Handle the PHP server login response
  95. //----------------------------------------------------------
  96. serverIn.onLoad = function(success)
  97. {
  98.     if (success)
  99.     {
  100.         if (this.res == "OK")
  101.         {
  102.             sendLogin()
  103.         }
  104.         else
  105.         {
  106.             var win:MovieClip = showWindow("errorWindow")
  107.             win.errorMsg.text = "Wrong name or passord"
  108.         }
  109.     }
  110.     else
  111.     {
  112.         var win:MovieClip = showWindow("errorWindow")
  113.         win.errorMsg.text = "Connection failed"
  114.     }
  115. }
  116.  
  117.  
  118.  
  119. //----------------------------------------------------------
  120. // Send login params to the server
  121. // server.login(zone, nickName, password)
  122. //----------------------------------------------------------
  123. function sendLogin()
  124. {
  125.     if (!_global.isBusy)
  126.         smartfox.login(zone, login_txt.text, pwd_txt.text)
  127. }
  128.  
  129.  
  130.  
  131. //----------------------------------------------------------
  132. // Handle login response from server
  133. //----------------------------------------------------------
  134. smartfox.onLogin = function(resObj:Object)
  135. {
  136.     if (resObj.success)
  137.     {
  138.         // Login Successfull
  139.         _global.myName = resObj.name
  140.     }
  141.     else
  142.     {
  143.         // Login Failed
  144.         _gloabl.isBusy = true
  145.        
  146.         // Show an error window
  147.         var win = showWindow("errorWindow")
  148.         win.errorMsg.text = resObj.error
  149.     }
  150. }
  151.  
  152. //----------------------------------------------------------
  153. // Handle the onRoomListUpdate here and keep it in the
  154. // queue. We'll handle it in the next frame.
  155. //----------------------------------------------------------
  156. smartfox.onRoomListUpdate = function(o:Object)
  157. {
  158.     evtQueue.push(o)
  159.     gotoAndStop("chat")
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------
  164. // Handle unexpected server disconnection
  165. //----------------------------------------------------------
  166. smartfox.onConnectionLost = function()
  167. {
  168.     gotoAndStop("connect")
  169. }
  170.  
  171.  
  172.  
  173. //----------------------------------------------------------
  174. // Show / Hides the login input field and submit button
  175. //----------------------------------------------------------
  176. function showLogin(bool:Boolean)
  177. {
  178.     butt_login._visible = bool
  179.     login_txt._visible = bool
  180.     pwd_txt._visible = bool
  181.    
  182.     if (bool)
  183.         Selection.setFocus("login_txt")
  184. }
  185.  
  186.  
  187.  
  188. //----------------------------------------------------------
  189. // Shows a popup window and disables all other controls
  190. //----------------------------------------------------------
  191. function showWindow(linkageName:String):MovieClip
  192. {
  193.     _global.isBusy = true
  194.    
  195.     userList_lb.setEnabled(false)
  196.     disabler._visible = true
  197.    
  198.     var win = _root.attachMovie(linkageName, linkageName, 9999)
  199.        
  200.     win._x = (stageW / 2) - (win._width / 2)
  201.     win._y = (stageH / 2) - (win._height / 2)
  202.    
  203.     return win
  204. }
  205.  
  206.  
  207.  
  208. //----------------------------------------------------------
  209. // Hides a popup window and re-enable the controls
  210. //----------------------------------------------------------
  211. function hideWindow(wName:String)
  212. {
  213.     this[wName].removeMovieClip()
  214.     disabler._visible = false
  215.     _global.isBusy = false
  216.    
  217.     userList_lb.setEnabled(true)
  218. }
  219.  
  220.  

y el codigo del login.php:
Código: Text
  1. <?php
  2. $dbhost="localhost";  
  3. $dbusuario="myuser";
  4. $dbpassword="mypass";
  5. $db="mydb";
  6. $conexion = mysql_connect($dbhost, $dbusuario, $dbpassword);
  7. mysql_select_db($db, $conexion);
  8. $usuario = $_POST["name"];
  9. $pass = md5($_POST["pass"]);
  10. $consulta_usuario ="SELECT * FROM usuarios WHERE nick = '$usuario' AND password = '$pass'";
  11. $result = mysql_query($consulta_usuario) or die("Couldn't execute query.");
  12. $num_rows = mysql_num_rows($result);
  13. if($num_rows == 0){
  14. $res = "res=KO";
  15. }else{
  16. if($num_rows > 0){
  17. $res = "res=OK";
  18. }
  19. mysql_close($conexion);
  20. }
  21. ?>
  22.  

Muchas Gracías
Saludos.