| 27 | | telnet.terminal.setFocus(); |
| | 32 | } |
| | 33 | |
| | 34 | private function popUpDialog(message:String):void |
| | 35 | { |
| | 36 | var dialog:ConnectionDialog = PopUpManager.createPopUp( |
| | 37 | this, |
| | 38 | ConnectionDialog, |
| | 39 | true |
| | 40 | ) as ConnectionDialog; |
| | 41 | dialog.addEventListener(ConnectionDialog.CONNECT_START, dialogHandler); |
| | 42 | dialog.x = (this.width - dialog.width) / 2 |
| | 43 | dialog.y = (this.height - dialog.height) / 2 |
| | 44 | dialog.message.text = message; |
| | 45 | if(_host) { |
| | 46 | dialog.host.text = _host; |
| | 47 | } |
| | 48 | if(_port) { |
| | 49 | dialog.port.text = String(_port); |
| | 50 | } |
| | 51 | } |
| | 52 | |
| | 53 | private function dialogHandler(event:Event):void |
| | 54 | { |
| | 55 | _host = event.target.host.text; |
| | 56 | _port = Number(event.target.port.text); |
| | 57 | PopUpManager.removePopUp(IFlexDisplayObject(event.target)); |
| | 58 | connect(); |
| | 59 | } |
| | 60 | |
| | 61 | private function connect():void |
| | 62 | { |
| | 63 | panel.connect(_host, _port); |
| | 64 | panel.telnet.addEventListener(Event.CONNECT, connectHandler); |
| | 65 | panel.telnet.addEventListener(Event.CLOSE, closeHandler); |
| | 66 | panel.telnet.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); |
| | 67 | panel.telnet.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); |
| | 68 | panel.terminal.setFocus(); |
| | 69 | } |
| | 70 | |
| | 71 | private function connectHandler(event:Event):void |
| | 72 | { |
| | 73 | panel.terminal.setFocus(); |
| | 74 | } |
| | 75 | |
| | 76 | private function closeHandler(event:Event):void |
| | 77 | { |
| | 78 | popUpDialog("Connection closed."); |
| | 79 | } |
| | 80 | |
| | 81 | private function ioErrorHandler(event:IOErrorEvent):void |
| | 82 | { |
| | 83 | popUpDialog("IO Error: " + event.text); |
| | 84 | } |
| | 85 | |
| | 86 | private function securityErrorHandler(event:SecurityErrorEvent):void |
| | 87 | { |
| | 88 | popUpDialog("Security Error: " + event.text); |