Copy link to clipboard
Copied
Hi,
I've got an AIR map that displays the tides.
The tides are in an xml file that I embed to my apk or ipa like this :
I'd like to have the possibility to overwrite this file. Problem : I don't know if AIR allows me to write or overwrite anything in the app directory.
I've tried this :
function startDownload():void{
var urlString:String = "http://mywebsite/horaires3.xml";
var urlReq:URLRequest = new URLRequest(urlString);
var urlStream:URLStream = new URLStream();
var fileData:ByteArray = new ByteArray();
urlStream.addEventListener(Event.COMPLETE, loaded);
urlStream.load(urlReq);
function loaded(event:Event):void {
urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
writeFile();
}
function writeFile():void {
var file:File = File.applicationStorageDirectory.resolvePath("horaires3.xml");
var fileStream:FileStream = new FileStream()
fileStream.open(file, FileMode.WRITE);
urlRemote_txt.text = file.url;
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
trace("The AIR file is written.");
}
}
The new xml file is downloaded, no errors, but it doesn't seems to replace the original xml of the app..
link of the downloaded xml = app-storage:/horaires3.xml
link of the original xml = horaires3.xml
So, what do you suggest me to do ?
Is there a way to overwrite it ?
Copy link to clipboard
Copied
Pretty sure you can't on iOS, and possibly not an Android either. The normal approach would be to copy the file to the application's storage directory. Read this article:
File - Adobe ActionScript® 3 (AS3 ) API Reference
but there isn't an exact example for what you need. It's the middle of the night for me at the moment, but I have had to do something similar. If you can't work it out I'll try to find some of my code in the morning.
Copy link to clipboard
Copied
Ok Thx. I'll try it tomorrow (night for me too)
I'll let you know