<?
xml version
=
"
1.0
"
encoding
=
"
utf-8
"
?>
<
mx:Application xmlns:mx
=
"
http://www.adobe.com/2006/mxml
"
layout
=
"
absolute
"
>
<
mx:Label x
=
"
10
"
y
=
"
10
"
text
=
"
服务器:
"
width
=
"
53
"
fontSize
=
"
12
"
/>
<
mx:TextInput x
=
"
71
"
y
=
"
10
"
width
=
"
208
"
editable
=
"
true
"
id
=
"
Server
"
/>
<
mx:TextInput x
=
"
71
"
y
=
"
38
"
width
=
"
208
"
editable
=
"
true
"
id
=
"
UserName
"
/>
<
mx:TextInput x
=
"
71
"
y
=
"
66
"
width
=
"
208
"
editable
=
"
true
"
id
=
"
Password
"
displayAsPassword
=
"
true
"
/>
<
mx:HRule x
=
"
10
"
y
=
"
94
"
width
=
"
538
"
/>
<
mx:TextArea x
=
"
10
"
y
=
"
104
"
width
=
"
538
"
height
=
"
280
"
id
=
"
DebugText
"
/>
<
mx:Button x
=
"
287
"
y
=
"
65
"
label
=
"
连 接
"
id
=
"
Submit
"
click
=
"
Send()
"
/>
<
mx:Style
>

Application
...
{
backgroundColor: #869ca7;
backgroundGradientColors: #6666ff, #ff3399;
themeColor: #66ff00;
color: #0b333c;
}

Button
...
{
fontSize: 12;
}
</
mx:Style
>
<
mx:Script
>
<!
[CDATA[
import
mx.events.IndexChangedEvent;
import
flash.net.
*
;
import
flash.utils.ByteArray;
import
mx.controls.Alert;
private
var hostname:String;
private
var port:
int
=
21
;
private
var username:String;
private
var password:String;
private
var socket:Socket;
private
var State:String;
private
var str:String;
private
var event:Event;

public
function Send():
void
...
{
hostname = Server.text;
username = UserName.text;
password = Password.text;
socket = new Socket;
AddListeners(socket);
socket.connect(hostname,port);
traces("连接"+hostname+"中");
}

private
function AddListeners(event:IEventDispatcher):
void
...
{
socket.addEventListener("connect", OnConnect);
socket.addEventListener("progress", DataActive);
socket.addEventListener("socketData", RevData);
socket.addEventListener("ioError", Err);
socket.addEventListener("securityError", Err);
}

private
function OnConnect(event:Event):
void
...
{
traces("连接成功"+event);
}

private
function RevData (event:Event):
void
...
{
traces("接收数据"+event);
var input:String="";
while ( socket.bytesAvailable > 0 )
...{
var byte: uint = socket.readUnsignedByte();
var next: uint;
input += String.fromCharCode( byte );
}
State=input.substr(0,3);
//Alert.show(State,"Debug");
traces("接收数据:"+input);
DataActive(State);
}

private
function DataActive(State:String):
void
...
{
traces("发送数据状态激活");
switch (State)...{
case "220":
...{
str = "USER "+username+" ";
break;
}
case "331":
...{
str = "PASS "+password+" ";
break;
}
case "230":
...{
str = "PWD ";
break;
}
case "227":
...{
str = "LIST ";
break;
}
case "257":
...{
str = "REST 0 ";
break;
}
case "350":
...{
str = "PASV ";
break;
}
case "530":
...{
str = "USER "+username+" ";
break;
}
}
socket.writeMultiByte(str,"iso-8859-2");
socket.flush();
State == "331" ? traces("发送数据******") : traces("发送数据"+str);
}

private
function Err(event:Event):
void
...
{
traces("错误:"+event);
}

private
function traces(msg:String):
void
...
{
DebugText.text = DebugText.text + " " + msg;
}
]]
>
</
mx:Script
>
<
mx:Label x
=
"
10
"
y
=
"
38
"
text
=
"
用户名:
"
fontSize
=
"
12
"
/>
<
mx:Label x
=
"
18
"
y
=
"
66
"
text
=
"
密 码:
"
fontSize
=
"
12
"
/>
</
mx:Application
>


185

被折叠的 条评论
为什么被折叠?



