Changeset 7241

Show
Ignore:
Timestamp:
02/28/08 17:33:24 (5 years ago)
Author:
frsyuki
Message:

lang/actionscript/FxTerm: added example connection dialog

Location:
lang/actionscript/FxTerm/trunk
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • lang/actionscript/FxTerm/trunk/Example.mxml

    r7237 r7241  
    11<?xml version="1.0" encoding="utf-8"?> 
    22<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    3                 initialize="init()" xmlns="*" 
     3                creationComplete="init()" xmlns="*" 
    44        > 
    55        <mx:Style> 
     
    1414        <mx:Script> 
    1515        <![CDATA[ 
     16                import ConnectionDialog; 
     17                import mx.managers.PopUpManager; 
     18                import mx.core.*; 
     19                private var _host:String; 
     20                private var _port:Number; 
    1621                private function init():void 
    1722                { 
     
    1924                        var port:String = Application.application.parameters.port; 
    2025                        if(host && port) { 
    21                                 telnet.connect(host, Number(port)); 
     26                                _host = host; 
     27                                _port = Number(port); 
     28                                connect(); 
    2229                        } else { 
    23                                 //telnet.connect("localhost", 12880); 
    24                                 telnet.connect("localhost", 2751); 
    25                                 //telnet.connect("localhost", 23); 
     30                                popUpDialog("Connect to host."); 
    2631                        } 
    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); 
    2889                } 
    2990        ]]> 
    3091        </mx:Script> 
    3192 
    32         <TelnetPanel id="telnet"/> 
     93        <TelnetPanel id="panel"/> 
    3394 
    3495</mx:Application>