默认情况下从applicationStorageDirectory
如果它不存在 donwload 加载它并将 xml 保存到applicationStorageDirectory
装载:
var xmlFile:File = File.applicationStorageDirectory.resolvePath("data.xml");
if (xmlFile.exists)
{
var fileStream:FileStream = new FileStream();
fileStream.open(xmlFile, FileMode.READ);
var xml:XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));// you will want to declare outside this scope, its just for show
fileStream.close();
}else{
downloadAndSaveXML();// if it doesnt exist dowload it then save it and call load again!
}
保存:
//download .xml first and save in the onComplete handler, im calling the file "xml"
var file:File = File.applicationStorageDirectory.nativePath("data.xml");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes(xml.toXMLString());
stream.close();
明白了吗?
您还需要此编译器参数,因此 HTTPService 不会在线查找 xml
-locale en_US -use-network=false
您不必首先下载文件并将其嵌入到应用程序中
这里是该主题的链接