Skip to main content
Inspiring
October 19, 2016
Question

Methods to download assets from Internet in Air for IOS

  • October 19, 2016
  • 3 replies
  • 891 views

Dear Friends,

Greetings! kindly advice me the ways and methods to download assets (swf files) from internet when running the app first time in IPAD.

I tried to write files in to IPAD using write bytes (byte array). iam opening filestream in write mode.

i.e.

fileStream.writeBytes(data_val, 0, data_val.length);

it is not allowing the script (AS3) to copy in to IPAD. Pls suggest me what are all other methods to download assets(swf files) from internet.

Thanks in advance,

Thanks and Regards,

Syed Abdul Rahim

This topic has been closed for replies.

3 replies

rahimhajiAuthor
Inspiring
October 24, 2016

Mr.kglad,

I tried, it is not working, I don't want to load a swf and attach in app, I want to download the swf file with action script to IPAd and load the same file when ever I want.

Thanks and Regards,

Syed Abdul Rahim

kglad
Community Expert
Community Expert
October 24, 2016

what exactly is not working?

rahimhajiAuthor
Inspiring
October 20, 2016

Dear Mr.Kglad,

Greetings! thks for the reply. Already iam using loader class with loadercontext, pls check my previous post...

URLLoader is not working Air for IOS but working in computer

its is working with computer not working with IPAD. when I down load files from internet its is not allowing script for secondary swf files.. My logic is download swf assests (which contains AS script, animation & sound) from internet to reduce my app size, in IPAD it is downloading and saving in application storage directory, it is downloading only animation and sound not script.. it keep moving without even stop..

pls help me to solve this.

Thanks in advance,

Syed Abdul Rahim

kglad
Community Expert
Community Expert
October 20, 2016

copy and paste the code related to your loader.

rahimhajiAuthor
Inspiring
October 21, 2016

Hi Kglad,

Greetings!, code is available below:

import flash.display.Loader;
import flash.net.URLLoader;
import flash.filesystem.*;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.system.LoaderContext;

downloadFile("http://www.examplesite.com/test.swf");

//---------------------------------Downloading files - Starts------------------------------------------------
function downloadFile(file_location): void {
var urlLoader: URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, download_completed);
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(new URLRequest(file_location));
}

function download_completed(event: Event): void {
var data: ByteArray = event.target.data;
copy_files(data, "test.swf");
}

function copy_files(data_val, path) {
var fileStream: FileStream = new FileStream();
txt.text = "something copied...";
fileStream.open(File.applicationStorageDirectory.resolvePath(path), FileMode.WRITE);
fileStream.writeBytes(data_val, 0, data_val.length);
fileStream.close();
down_data();
txt.text =" something copied... " + File.applicationStorageDirectory.resolvePath(path).exists;
//---------------------------------Downloading files - Ends------------------------------------------------
menu1_les1.addEventListener(MouseEvent.CLICK, m1click);
function m1click(event: MouseEvent) {
req.url = "app-storage:/test.swf";
ldr.load(req, lc);
addChild(ldr);
}

Just create a new Air for IOS copy paste this, create one button(menu1_les1) and one text box (txt) on the state. it will work.  For ur info, I can download and load the same file in windows. But in IOS tab I can down load and load the files, but loaded files are swf with only image and animation script is not working. I have a doubt may be writing as binary is may be the issue. pls help me to solve this.

Thanks and Regards,

Syed Abdul Rahim

kglad
Community Expert
Community Expert
October 19, 2016

use the loader class to load swfs.

if there's actionscript in the loaded swf, use a loadercontext, http://blogs.adobe.com/airodynamics/2012/11/09/packaging-and-loading-multiple-swfs-in-air-apps-on-ios/