<?xml version= encoding=utf?>
<mx:Application xmlns:mx= layout=absolute
fontSize= creationComplete=initApp(); >
<mx:Script>
<![CDATA[
import ntrolsAlert;
import Socket;
import flashutilsByteArray;
import flasheventsKeyboardEvent;
//import flashsystemSecurity;
private var socket:Socket=new Socket();
internal function readConf():void
{
// var host:String = client_paralastResultSocketClienthost;
}
internal function initApp():void
{
// SecurityloadPolicyFile();
/// Alert(host);
//var port:int = client_paralastResultSocketClientport;
//Alert(port);
myInputaddEventListener(KeyboardEventKEY_DOWNsendMessageUseEnterKey);
nnect();
socketaddEventListener(EventCONNECTfunConnect);
socketaddEventListener(EventCLOSEfunClose);
socketaddEventListener(ProgressEventSOCKET_DATAfunSocket);
}
internal function funConnect(event:Event):void
{
myTexttext+=连接已建立 \n;
}
internal function funClose(event:Event):void
{
myTexttext+=连接已关闭 \n;
}
internal function sendMessage(msg:String):void
{
var message:ByteArray=new ByteArray();
messagewriteUTFBytes(msg+\n);
socketwriteBytes(message);
socketflush();
myInputtext=;
}
internal function funSocket(event:ProgressEvent):void
{
var msg:String=;
while(socketbytesAvailable)
{
msg+=socketreadMultiByte(socketbytesAvailableutf);
var arr:Array=msgsplit(\n);
for(var i:int=;i<arrlength;i++)
{
if(arr[i]length>)
{
var myPattern:RegExp=/\r/;
arr[i]=arr[i]replace(myPattern);
myTexttext+=arr[i]+\n;
}
}
myTextverticalScrollPosition = myTextmaxVerticalScrollPosition;//滚动到最下面
}
}
private function sendMessageUseEnterKey(evt:KeyboardEvent):void{
if(evtkeyCode==){
sendMessage(myNametext+:+myInputtext);
}
}
]]>
</mx:Script>
<!<mx:HTTPService id=client_para url=confxml useProxy=false/>>
<mx:Panel width= height= horizontalCenter= verticalCenter= layout=absolute verticalAlign=middle horizontalAlign=center>
<mx:TextArea y= width= height= id=myText horizontalCenter=/>
<mx:TextInput x= y= width= id=myInput/>
<mx:Button label=Send id=myBtn click=sendMessage(myNametext+:+myInputtext) x= y=/>
<mx:TextInput width= text=Name id=myName verticalCenter= horizontalCenter=/>
</mx:Panel>
</mx:Application>