Skip to main content
Participant
March 13, 2014
Question

Loading resources from server and storing them locally

  • March 13, 2014
  • 1 reply
  • 455 views

Hello,

I am working on iOS application.

I want to load some resources from external server. Let's say I have "assets.swf" that I put on my server.

In my app I want to load assets.swf file and use all the resources inside.

In the same time I want to save assets.swf in the local file system so my app can load it next time locally even if the device is offline.

I found this document External hosting of secondary SWFs for AIR apps on iOS which explains the first part of my question. However the document doesn't explain if it is possible to save and use the swf files locally and how to do it.

Can you give me some examples. Thank you in advance.

This topic has been closed for replies.

1 reply

Known Participant
March 23, 2014

Hi

You have to use the URLLoader. I've only tried this with images but it should work for swf's as well.

Something like this;

var loadUrl:String = "http://logowik.com/uploads/images/438_adobeair.jpg"

var fileName:String = "test.jpg"; // output file.

var loader:URLLoader= new URLLoader();

loader.dataFormat = URLLoaderDataFormat.BINARY;

loader.addEventListener(Event.COMPLETE, fileLoadComplete);

var req:URLRequest = new URLRequest (loadUrl);       

loader.load (req);

function fileLoadComplete(e:Event):void {

     var dataContent:ByteArray = e.target.data;

     // save the file in the application Directory  (It might be better to save it in the temp directory )

     var f:File = File.applicationStorageDirectory.resolvePath (fileName);

     var fs:FileStream = new FileStream();

     fs.open(f, FileMode.WRITE)

     fs.writeBytes(dataContent);

     fs.close();

}

Then load the image (or swf) as you do from the web.(Loader)

var f:File = File.applicationStorageDirectory.resolvePath (fileName);

Then use f.url as the url.