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