我试图通过HTTP为我的Flex应用程序检索二进制数据,但遇到了一些障碍。人们说使用URLLoader,HTTPService似乎不能很好地处理二进制数据。但是URLLoader没有HTTPService提供的很好的异步令牌/IResponder接口。
因此,我做了一些搜索,但没有找到任何扩展URLLoader来提供这种功能的人。我走在前面,亲自尝试了一下:http://pastebin.com/d7369d0e0
基本上,它包装了一个URLLoader和一个AsyncToken,并将COMPLETE、IO_ERROR和SECURITY_ERROR事件从URLLoader映射到在AsyncToken上引发的结果/错误。
基本用法:
var tidbitLoader:AsyncURLLoader = new AsyncURLLoader();
tidbitLoader.dataFormat = URLLoaderDataFormat.BINARY;
var asyncToken:AsyncToken = tidbitLoader.load(new URLRequest("http://localhost/SampleTidbit.swf"));
asyncToken.addResponder(this);
public function result(resultEvent:Object):void
{
trace("result");
}
public function fault(faultEvent:Object):void
{
var fault:FaultEvent = faultEvent as FaultEvent;
trace("fault: " + fault.toString());
}这是解决问题的正确方法吗?有没有现有的解决方案?我很乐意听到反馈。
谢谢,
卡尔蒂克
发布于 2009-12-31 00:04:02
在HTTPService上使用resultFormat = text,然后创建一个新的ByteArray,并调用writeUTFBytes将HTTPService结果中的文本写入ByteArray。然后,您应该能够将该ByteArray设置为SWFLoader.source或调用Loader.loadBytes。
发布于 2010-01-28 20:07:39
我已经用AIR 1.5应用程序尝试了你的解决方案,但是当我在我的SWFLoader.source上设置ByteArray时,我得到了以下错误。有什么想法吗?我想我在某处读到AIR改变了HTTP报头,这可能是原因?谢谢,本。
调试应用程序'direct_http_channel‘通道发送消息:(mx.messaging.messages::HTTPRequestMessage)#0 body = (Object)#1 clientId = (null) contentType = "application/x-www-form-urlencoded“destination = "DefaultHTTP”headers = (Object)#2 httpHeaders = (Object)#3 messageId = "3044E76C-CF0E-2D5F-96BE-74CFF62098B0“method = "GET”recordHeaders = false timestamp =0 timeToLive =0 url = "http://www.myurl.com/test.jpg“信息mx.messaging.Producer '4FA2CCF4-2B3E-4EAB-2873-74CFF612AA72‘生产者已连接。信息mx.messaging.Producer '4FA2CCF4-2B3E-4EAB-2873-74CFF612AA72‘生产者确认'3044E76C-CF0E-2D5F-96BE-74CFF62098B0’。信息mx.rpc.http.HTTPService解码HTTPService响应调试mx.rpc.http.HTTPService处理HTTPService响应消息:(mx.messaging.messages::AcknowledgeMessage)#0 body =“错误#2044:未处理的IOErrorEvent:. text=Error #2124:加载的文件是未知类型。
https://stackoverflow.com/questions/1959659
复制相似问题