
Flash as3 通过XMLSocket与Servlet(java)交互的问题
我们的课程项目是做一个网页游戏,现在碰到flash与后台的数据交互问题很棘手。在本地测试中,flash能够收到servlet的XML文件并输出数据,但通过域名访问的时候监...
我们的课程项目是做一个网页游戏,现在碰到flash与后台的数据交互问题很棘手。在本地测试中,flash能够收到servlet的XML文件并输出数据,但通过域名访问的时候监听服务器已经发送了XML,但Flash却没有响应,应该是没有收到XML的关系。请问下这种问题该怎么解决,附代码:
Flash:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.net.XMLSocket;
import flash.xml.XMLDocument;
//import flash.accessibility.*;
import flash.system.Security;
public class test1 extends MovieClip
{
private var socket:XMLSocket;
private var hostName:String = "localhost";//地址未填
private var port:uint = 8081;//端口号未填
public function test1()
{
// constructor code
socket = new XMLSocket();
configureListener(socket);
if (hostName && port)
{
socket.connect(hostName,port);
}
ButtonInput.addEventListener(MouseEvent.CLICK,FlashToJs);
}
private function configureListener(evt:IEventDispatcher):void
{
evt.addEventListener(Event.CLOSE, closeHandler);
evt.addEventListener(Event.CONNECT, connectHandler);
evt.addEventListener(DataEvent.DATA, dataHandler);
evt.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
private function FlashToJs(evt:MouseEvent):void
{
if (TxtInput.text == "")
{
//不做操作
}
else
{
socket.send(new XMLDocument("<a>" + TxtInput.text + "</a>\n"));
TxtInput.text = "";
}
}
private function closeHandler(event:Event):void
{
//TxtOutput.text = "连接断开\n";
}
private function connectHandler(event:Event):void
{
TxtOutput.text = "连接成功\n";
//socket.send("<policy-file-request />\n");
}
private function dataHandler(event:DataEvent):void
{
TxtOutput.appendText("Get!\n");
var xml:XMLDocument = new XMLDocument(event.data);
TxtOutput.appendText(xml.firstChild.firstChild.nodeValue);
}
private function ioErrorHandler(event:IOErrorEvent):void
{
TxtOutput.text = "连接失败\n";
}
// private function progressHandler(event:ProgressEvent):void {
// trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
// }
// private function securityErrorHandler(event:SecurityErrorEvent):void {
// trace("securityErrorHandler: " + event);
// }
}
} 展开
Flash:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.net.XMLSocket;
import flash.xml.XMLDocument;
//import flash.accessibility.*;
import flash.system.Security;
public class test1 extends MovieClip
{
private var socket:XMLSocket;
private var hostName:String = "localhost";//地址未填
private var port:uint = 8081;//端口号未填
public function test1()
{
// constructor code
socket = new XMLSocket();
configureListener(socket);
if (hostName && port)
{
socket.connect(hostName,port);
}
ButtonInput.addEventListener(MouseEvent.CLICK,FlashToJs);
}
private function configureListener(evt:IEventDispatcher):void
{
evt.addEventListener(Event.CLOSE, closeHandler);
evt.addEventListener(Event.CONNECT, connectHandler);
evt.addEventListener(DataEvent.DATA, dataHandler);
evt.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
//dispatcher.addEventListener(ProgressEvent.PROGRESS, progressHandler);
// dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
private function FlashToJs(evt:MouseEvent):void
{
if (TxtInput.text == "")
{
//不做操作
}
else
{
socket.send(new XMLDocument("<a>" + TxtInput.text + "</a>\n"));
TxtInput.text = "";
}
}
private function closeHandler(event:Event):void
{
//TxtOutput.text = "连接断开\n";
}
private function connectHandler(event:Event):void
{
TxtOutput.text = "连接成功\n";
//socket.send("<policy-file-request />\n");
}
private function dataHandler(event:DataEvent):void
{
TxtOutput.appendText("Get!\n");
var xml:XMLDocument = new XMLDocument(event.data);
TxtOutput.appendText(xml.firstChild.firstChild.nodeValue);
}
private function ioErrorHandler(event:IOErrorEvent):void
{
TxtOutput.text = "连接失败\n";
}
// private function progressHandler(event:ProgressEvent):void {
// trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
// }
// private function securityErrorHandler(event:SecurityErrorEvent):void {
// trace("securityErrorHandler: " + event);
// }
}
} 展开
3个回答
展开全部
害羞的鲤鱼目瞪口呆
都无需说:终于.
它们是一个蜂窝,
然而你的天真受到欣赏,你的根被
明亮的月亮
的么于是天富足的的活哈哈
都无需说:终于.
它们是一个蜂窝,
然而你的天真受到欣赏,你的根被
明亮的月亮
的么于是天富足的的活哈哈
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询