Skip to main content
Inspiring
Oct 19, 2016 5:50 AM UTC
Question

Methods to download assets from Internet in Air for IOS

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 is closed to new replies. Start a new post to keep the conversation going.

9 replies

rahimhajiAuthor
Inspiring
Oct 24, 2016 5:17 AM UTC

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

Translate
kglad
Community Expert
Community Expert
Oct 24, 2016 3:19 PM UTC

what exactly is not working?

Translate
rahimhajiAuthor
Inspiring
Oct 20, 2016 6:48 AM UTC

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

Translate
kglad
Community Expert
Community Expert
Oct 20, 2016 2:02 PM UTC

copy and paste the code related to your loader.

Translate
rahimhajiAuthor
Inspiring
Oct 21, 2016 1:25 PM UTC

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

Translate
kglad
Community Expert
Community Expert
Oct 19, 2016 2:19 PM UTC

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/

Translate