ConnectionScreen.as 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import flash.external.*;
  2. import gfx.controls.TextInput;
  3. import gfx.controls.Button;
  4. import gfx.controls.ProgressBar;
  5. import mx.transitions.easing.None;
  6. import mx.transitions.Tween;
  7. class Screens.ConnectionScreen extends Screen
  8. {
  9. private var mcConnect:Button;
  10. private var mcCancel:Button;
  11. //private var mcProgress:ProgressBar;
  12. private var mcProgressBar:MovieClip;
  13. private var tfConnectionFailed:TextField;
  14. private var tfAddress:TextField;
  15. private var tfPort:TextField;
  16. public function ConnectionScreen()
  17. {
  18. ConsoleWindow.Trace("Constructing ConnectionScreen");
  19. mScreenId = ScreenID.CONNECTION;
  20. mScreenTabId = ScreenTab.ID_CONNECTION;
  21. tfConnectionFailed._visible = false;
  22. }
  23. public function VOnFinishedLoading():Void
  24. {
  25. mcConnect.addEventListener("click", this, "f2c_Connect");
  26. //Add callbacks for C++
  27. ExternalInterface.addCallback("c2f_NotifyConnectingToServer", this, c2f_NotifyConnectingToServer);
  28. ExternalInterface.addCallback("c2f_NotifyConnectionResultFailure", this, c2f_NotifyConnectionResultFailure);
  29. ExternalInterface.addCallback("c2f_NotifyConnectionResultSuccess", this, c2f_NotifyConnectionResultSuccess);
  30. super.VOnFinishedLoading();
  31. }
  32. public function OnShow():Void
  33. {
  34. //ConsoleWindow.Trace( mcProgressBar.mcBar);
  35. mcProgressBar.mcBar._xscale = 0;
  36. }
  37. public function f2c_Connect():Void
  38. {
  39. new Tween( mcProgressBar.mcBar, "_xscale", None.easeNone, 0, 100, 6, true );
  40. //mcProgress.setProgress( 2, 6 );
  41. ConsoleWindow.Trace("connecting to server");
  42. //ExternalInterface.call("f2c_Connect", "127.0.0.1", "60481");
  43. ExternalInterface.call("f2c_Connect", tfAddress.text, tfPort.text);
  44. if ( LobbyInterface.Instance.IsInFlashMode() )
  45. {
  46. LobbyInterface.Instance.ShowScreen( ScreenID.LOGIN );
  47. }
  48. }
  49. public function c2f_NotifyConnectingToServer():Void
  50. {
  51. //_root.gotoAndPlay("ConnectingToServer");
  52. //LobbyInterface.Instance.ShowScreen( ScreenID.CONNECTING_TO_SERVER );
  53. }
  54. function c2f_NotifyConnectionResultFailure(resultIdentifier:String):Void
  55. {
  56. switch (resultIdentifier)
  57. {
  58. case "CONNECTION_ATTEMPT_FAILED":
  59. break;
  60. case "ALREADY_CONNECTED":
  61. break;
  62. case "NO_FREE_INCOMING_CONNECTIONS":
  63. break;
  64. case "RSA_PUBLIC_KEY_MISMATCH":
  65. break;
  66. case "CONNECTION_BANNED":
  67. break;
  68. case "INVALID_PASSWORD":
  69. break;
  70. }
  71. tfConnectionFailed.text=resultIdentifier;
  72. tfConnectionFailed._visible=true;
  73. }
  74. function c2f_NotifyConnectionResultSuccess():Void
  75. {
  76. ConsoleWindow.Trace("ConnectionScreen... calling login");
  77. LobbyInterface.Instance.ShowScreen( ScreenID.LOGIN );
  78. }
  79. }
粤ICP备19079148号