root/lang/actionscript/FxTerm/trunk/Example.mxml @ 7767

Revision 7767, 2.3 kB (checked in by frsyuki, 5 years ago)

lang/actionscript/FxTerm: created package directory

Line 
1<?xml version="1.0" encoding="utf-8"?>
2<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
3                xmlns:tty="org.partty.mxml.*"
4                creationComplete="init()"
5        >
6        <mx:Style>
7        <![CDATA[
8                Application {
9                        backgroundColor: #999999;
10                        backgroundAlpha: 0;
11                        backgroundGradientAlphas: 0.0, 0.0;
12                }
13        ]]>
14        </mx:Style>
15        <mx:Script>
16        <![CDATA[
17                import ConnectionDialog;
18                import mx.managers.PopUpManager;
19                import mx.core.*;
20                private var _host:String;
21                private var _port:Number;
22                private function init():void
23                {
24                        var host:String = Application.application.parameters.host;
25                        var port:String = Application.application.parameters.port;
26                        if(host && port) {
27                                _host = host;
28                                _port = Number(port);
29                                connect();
30                        } else {
31                                popUpDialog("Connect to host.");
32                        }
33                }
34
35                private function popUpDialog(message:String):void
36                {
37                        var dialog:ConnectionDialog = PopUpManager.createPopUp(
38                                        this,
39                                        ConnectionDialog,
40                                        true
41                                        ) as ConnectionDialog;
42                        dialog.addEventListener(ConnectionDialog.CONNECT_START, dialogHandler);
43                        dialog.x = (this.width - dialog.width) / 2
44                        dialog.y = (this.height - dialog.height) / 2
45                        dialog.message.text = message;
46                        if(_host) {
47                                dialog.host.text = _host;
48                        }
49                        if(_port) {
50                                dialog.port.text = String(_port);
51                        }
52                }
53
54                private function dialogHandler(event:Event):void
55                {
56                        _host = event.target.host.text;
57                        _port = Number(event.target.port.text);
58                        PopUpManager.removePopUp(IFlexDisplayObject(event.target));
59                        connect();
60                }
61
62                private function connect():void
63                {
64                        panel.connect(_host, _port);
65                        panel.telnet.addEventListener(Event.CONNECT, connectHandler);
66                        panel.telnet.addEventListener(Event.CLOSE, closeHandler);
67                        panel.telnet.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
68                        panel.telnet.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
69                        panel.terminal.setFocus();
70                }
71
72                private function connectHandler(event:Event):void
73                {
74                        panel.terminal.setFocus();
75                }
76
77                private function closeHandler(event:Event):void
78                {
79                        popUpDialog("Connection closed.");
80                }
81
82                private function ioErrorHandler(event:IOErrorEvent):void
83                {
84                        popUpDialog("IO Error: " + event.text);
85                }
86
87                private function securityErrorHandler(event:SecurityErrorEvent):void
88                {
89                        popUpDialog("Security Error: " + event.text);
90                }
91        ]]>
92        </mx:Script>
93
94        <tty:TelnetPanel id="panel"/>
95
96</mx:Application>
Note: See TracBrowser for help on using the browser.