grunerasta
22.06.2007, 14:17
Есть такое тестовое приложение, оно категорически отказывается работать с сокетом, который определенно есть (клиенты на сях работают). Кросдомен прописан, похожая конструкция из восьмого флеша работает.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application paddingBottom="20" paddingTop="20" paddingLeft="20" paddingRight="20" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.events.IOErrorEvent;
private var _socket:XMLSocket;
private var xmlString:String="<message value='Hello World'/>"
private function init():void
{
_socket=new XMLSocket();
_socket.addEventListener(DataEvent.DATA,onSocketData)
_socket.addEventListener(Event.CLOSE,onSocketClose);
_socket.addEventListener(Event.CONNECT,onSocketConnect)
_socket.addEventListener(IOErrorEvent.IO_ERROR,onSocketIOError)
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSocketSecurityError)
dataTextArea.text=new XML(xmlString).toXMLString()
}
private function sendData():void
{
xmlString=dataTextArea.text;
var data:XML=new XML(xmlString);
if(_socket.connected)
{
_socket.send(data);
}
}
private function showEvent(type:String,content:String):void
{
var date:Date=new Date();
var seconds:String = (date.getSeconds().toString().length <2)? '0'+date.getSeconds() : date.getSeconds().toString();
var minutes:uint = date.getMinutes();
var hours:uint = date.getHours();
var time:String=hours+":"+minutes+":"+seconds;
eventTextArea.text+=time+" "+content+'\n'
eventTextArea.text+='\n'
}
/*==================== Event Handlers ===================== */
private function onSocketData(event:DataEvent):void
{
showEvent(event.type,event.data);
}
private function onSocketClose(event:Event):void
{
showEvent(event.type,event.toString());
}
private function onSocketConnect(event:Event):void
{
showEvent(event.type,event.toString());
sendButton.enabled=true;
}
private function onSocketIOError(event:Event):void
{
showEvent(event.type,event.toString());
}
private function onSocketSecurityError(event:SecurityErrorEvent):void
{
showEvent(event.type,event.toString());
}
private function onConnectButtonClick():void
{
var host:String=hostTextInput.text;
var port:int=int(portTextInput.text as Number);
_socket.connect(host,port);
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:ApplicationControlBar>
<mx:HBox width="100%">
<mx:Label text="Host:"/>
<mx:TextInput id="hostTextInput" text="192.168.0.108" width="200"/>
<mx:Spacer width="10"/>
<mx:Label text="Port:"/>
<mx:TextInput id="portTextInput" text="1024" width="200"/>
<mx:VRule height="22"/>
<mx:Button id="connectButton" label="Connect" click="onConnectButtonClick()"/>
<mx:Button id="sendButton" label="Send" enabled="false" click="sendData()"/>
<mx:VRule height="22"/>
<mx:Button label="Clear" click="{eventTextArea.text=''}"/>
</mx:HBox>
</mx:ApplicationControlBar>
<mx:Panel headerHeight="10" width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
<mx:HDividedBox width="100%" height="100%">
<mx:Canvas width="80%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:TextArea id="eventTextArea" editable="false" width="100%" height="100%"/>
</mx:VBox>
</mx:Canvas>
<mx:Canvas width="20%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:TextArea id="dataTextArea" editable="true" width="100%" height="100%"/>
</mx:VBox>
</mx:Canvas>
</mx:HDividedBox>
</mx:Panel>
</mx:VBox>
</mx:Application>
Что делать???
<?xml version="1.0" encoding="utf-8"?>
<mx:Application paddingBottom="20" paddingTop="20" paddingLeft="20" paddingRight="20" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.events.IOErrorEvent;
private var _socket:XMLSocket;
private var xmlString:String="<message value='Hello World'/>"
private function init():void
{
_socket=new XMLSocket();
_socket.addEventListener(DataEvent.DATA,onSocketData)
_socket.addEventListener(Event.CLOSE,onSocketClose);
_socket.addEventListener(Event.CONNECT,onSocketConnect)
_socket.addEventListener(IOErrorEvent.IO_ERROR,onSocketIOError)
_socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,onSocketSecurityError)
dataTextArea.text=new XML(xmlString).toXMLString()
}
private function sendData():void
{
xmlString=dataTextArea.text;
var data:XML=new XML(xmlString);
if(_socket.connected)
{
_socket.send(data);
}
}
private function showEvent(type:String,content:String):void
{
var date:Date=new Date();
var seconds:String = (date.getSeconds().toString().length <2)? '0'+date.getSeconds() : date.getSeconds().toString();
var minutes:uint = date.getMinutes();
var hours:uint = date.getHours();
var time:String=hours+":"+minutes+":"+seconds;
eventTextArea.text+=time+" "+content+'\n'
eventTextArea.text+='\n'
}
/*==================== Event Handlers ===================== */
private function onSocketData(event:DataEvent):void
{
showEvent(event.type,event.data);
}
private function onSocketClose(event:Event):void
{
showEvent(event.type,event.toString());
}
private function onSocketConnect(event:Event):void
{
showEvent(event.type,event.toString());
sendButton.enabled=true;
}
private function onSocketIOError(event:Event):void
{
showEvent(event.type,event.toString());
}
private function onSocketSecurityError(event:SecurityErrorEvent):void
{
showEvent(event.type,event.toString());
}
private function onConnectButtonClick():void
{
var host:String=hostTextInput.text;
var port:int=int(portTextInput.text as Number);
_socket.connect(host,port);
}
]]>
</mx:Script>
<mx:VBox width="100%" height="100%">
<mx:ApplicationControlBar>
<mx:HBox width="100%">
<mx:Label text="Host:"/>
<mx:TextInput id="hostTextInput" text="192.168.0.108" width="200"/>
<mx:Spacer width="10"/>
<mx:Label text="Port:"/>
<mx:TextInput id="portTextInput" text="1024" width="200"/>
<mx:VRule height="22"/>
<mx:Button id="connectButton" label="Connect" click="onConnectButtonClick()"/>
<mx:Button id="sendButton" label="Send" enabled="false" click="sendData()"/>
<mx:VRule height="22"/>
<mx:Button label="Clear" click="{eventTextArea.text=''}"/>
</mx:HBox>
</mx:ApplicationControlBar>
<mx:Panel headerHeight="10" width="100%" height="100%" paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
<mx:HDividedBox width="100%" height="100%">
<mx:Canvas width="80%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:TextArea id="eventTextArea" editable="false" width="100%" height="100%"/>
</mx:VBox>
</mx:Canvas>
<mx:Canvas width="20%" height="100%">
<mx:VBox width="100%" height="100%">
<mx:TextArea id="dataTextArea" editable="true" width="100%" height="100%"/>
</mx:VBox>
</mx:Canvas>
</mx:HDividedBox>
</mx:Panel>
</mx:VBox>
</mx:Application>
Что делать???