我正在构建一个AIR应用程序,该应用程序将用于编辑另一个应用程序的幻灯片(也由我构建,但不在AIR中)。幻灯片和其他数据定义在其他应用程序的程序文件夹中的几个xml文件中。当试图将这些加载到我的AIR应用程序时,我得到以下错误:
fault(mx.messaging.messages::ErrorMessage)#0
body = ""
clientId = "DirectHTTPChannel0"
correlationId = "D67CFDDA-2A2E-9D8B-21DE-7D9FB4B72167"
destination = ""
extendedData = (null)
faultCode = "Server.Error.Request"
faultDetail = "Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: app:/Users/path/to/folder/languages.xml" errorID=2032]. URL: /Users/path/to/folder/languages.xml"
faultString = "HTTP request error"
headers = (Object)#1
DSStatusCode = 0
messageId = "F54EACC8-22F3-3718-9106-7D9FB4E0649C"
rootCause = (flash.events::IOErrorEvent)#2
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = ""
dataFormat = "text"
errorID = 2032
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2032: Stream Error. URL: app:/Users/path/to/folder/languages.xml"
type = "ioError"
timestamp = 0
timeToLive = 0
我是这样写的:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="windowedapplication1_creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
{
this.languages.addEventListener(FaultEvent.FAULT, this.faultHandler);
this.languages.addEventListener(ResultEvent.RESULT, resultHandler);
this.languages.send();
}
private function faultHandler(event:FaultEvent):void
{
trace("fault" + event.message);
}
private function resultHandler(event:ResultEvent):void
{
trace("success" + event.result);
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="languages" url="/Users/path/to/folder/languages.xml"/>
</fx:Declarations>
</s:WindowedApplication>
我如何从这些文件中读取?应用程序将不需要与任何东西通信,除了本地文件。
感谢J_A_X的回答,我把我的creationCompleteHandler改为:
var file:File = new File("/Users/path/to/folder/languages.xml");
var fs:FileStream = new FileStream();
fs.open(file, FileMode.READ);
var text:String = fs.readUTFBytes(file.size);
trace(text);
效果很好
HTTPService用于HTTP通信。获取本地文件不是HTTP。您需要查看File类来打开/读取xml。