Skip to main content
Inspiring
Oct 12, 2016 8:19 AM UTC
Question

URLLoader is not working Air for IOS but working in computer

Dear Friends,

iam trying to download files from internet and store it in IPAD. I used the below code it was loading sometimes back now its not working. Actually in computer iam getting the msg its downloaded in local. But in IPAD (IOS) its not downloading.... pls help me how to solve this...

import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.*;
import flash.events.Event;
import flash.utils.ByteArray;

var req: URLRequest = new URLRequest("http://www.abc.com/test.swf");
var urlLoader: URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(req);

urlLoader.addEventListener(Event.COMPLETE, url_loaded);

function url_loaded(event: Event) {
txt.text = "file loaded";
var data:ByteArray = event.target.data;
txt.text = data.toString();
}

Thanks and Regards,

Syed Abdul Rahim

This topic is closed to new replies. Start a new post to keep the conversation going.

14 replies

rahimhajiAuthor
Inspiring
Oct 18, 2016 12:45 PM UTC

Dear M/s.Deepika,

Greeings! thks for the help. Its working fine.  Please read my previous post. Even I store in application storage directory its working. only problem is its not stopping, running continuously because its IOS is allowing to write only animations and images in swf. it is not writing action script even stop() command, so its keep running without stopping and other script is not working.

Pls check your swf, it has got only animation and sound, there is no script or any interaction. pls tell me the way to download or write the swf file with script.

Thanks and Regards,

Syed Abdul Rahim

Translate
rahimhajiAuthor
Inspiring
Oct 19, 2016 4:42 AM UTC

hi deepika,

pls add a swf file which contains script (AS3) in it and see pls help me to solve this...

Thanks and Regards,

Syed Abdul Rahim

Translate
rahimhajiAuthor
Inspiring
Oct 13, 2016 11:36 AM UTC

HI deesharm,

Greetings! yes I have used Security.allowDomain...

its not working... still error:

please note that I have copied the files to ipad using fileStream.writeBytes...  will it create any problem? and loading the file using loader

my code is like below:

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();

}

loading is:

var ldr:loader = new loader();

var filePath = "assetstest.swf" + "?tt=" + Math.random();

  req = new URLRequest(filePath);

  req.cacheResponse = false;

  req.useCache = false;

  ldr.load(req, lc);

Thanks and Regards,

Syed Abdul Rahim

Translate
deesharm
Adobe Employee
Adobe Employee
Oct 13, 2016 3:59 PM UTC

Hi Syed,

Could you please share a sample application with us.

I will look into it further at my end.

Thanks,

Adobe AIR Team

Translate
rahimhajiAuthor
Inspiring
Oct 16, 2016 1:22 PM UTC

Hi deesharm,

Greetings, thks for the help, actually iam downloading files from internet (with the help of write byte array) and copying to storage directory of IPAD, and loading the same by using loader object.  pls check my codings below:

//---------------------------------Downloading files - Starts------------------------------------------------
var te: Number = 0;
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, menuXML.module.lesson.sfile[initFileNum].toString());
}

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();
initFileNum++;
down_data();
txt.text = initFileNum + " something copied... " + File.applicationStorageDirectory.resolvePath(path).exists + initFileNum;
}
//---------------------------------Downloading files - Ends------------------------------------------------

For Loading main frame
----------------------

var filePath = "assets/lmsframe.swf" + "?tt=" + Math.random();
req = new URLRequest(filePath);
req.cacheResponse = false;
req.useCache = false;
ldr.load(req, lc);
ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loading_ioerror);
ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loading_progress);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loading_finished);

Inside main frame loading the sub files:
----------------------------------------

loaders[loadedCount] = new Loader()
var lc3: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
lc3.allowCodeImport = true;
var fn;
if (MovieClip(parent.parent.parent) != null) {
fn = main_mc.storagePath + main_mc.currentClickedModule + fileNames[loadedCount] + "?tt=" + Math.random(); //--new addition for ios.
} else {
fn = main_mc.mainPath + main_mc.currentClickedModule + fileNames[loadedCount]
}

loaders[loadedCount].load(new URLRequest(String(fn)), lc3);
loaders[loadedCount].contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadingFiles)
loaders[loadedCount].contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoadComplete)
}

It is downloading (swf) and writing in application storage directory and loading fine when I loading, it is loading the swf fine in computer (image, animation and script). BUt in IPAD it is loading only image and animations in the swf script is not running. it is not even stopping keep running as loop.

pls help me.

Thanks and Regards,

Syed Abdul Rahim

Translate
rahimhajiAuthor
Inspiring
Oct 13, 2016 5:35 AM UTC

Hi yachts,

Greetings! thks for the reply. I tried https: its not working. Then I tried other option by adding

<key>NSAppTransportSecurity</key>

  <dict>

    <key>NSAllowsArbitraryLoads</key>

    <true/>

  </dict>

in InfoAdditions, its working fine.. Thanks a lot..

Then iam loading the copied files from applicationstorage directory.. its loading fine.. but giving sand box error like below:

*** Security Sandbox Violation ***

SecurityDomain 'app-storage:/lessons/m1_les1/swf/test.swf' tried to access incompatible context 'app:/down_5.swf'

SecurityError: Error #2070: Security sandbox violation: caller app-storage:/lessons/m1_les1/swf/test.swf cannot access Stage owned by app:/down_5.swf.

at flash.display::Stage/requireOwnerPermissions()

at flash.display::Stage/addEventListener()

Pls help me to solve this...

Thanks and Regards,

Syed Abdul Rahim

Translate
deesharm
Adobe Employee
Adobe Employee
Oct 13, 2016 5:45 AM UTC

Hi Syed,

Have you tried using security.allowDomain("*"); in your code?

Please try adding below lines:

import flash.system.Security;

Security.allowDomain("*");

If this works, you will want to change it from "*" to the specific domain of the swf you are loading.

Kindly let us know if it helps you.

Thanks,

Adobe AIR Team

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

hi yachts9999,

I tried with https, its not working...

Translate
Inspiring
Oct 12, 2016 1:28 PM UTC

Does the server you are trying to contact have a certificate installed?

Have you tried contacting the server using https in your browser as in

https://www.abc.com

Translate
Inspiring
Oct 12, 2016 12:18 PM UTC

The connection to a remote server must now use https not http when using URLLoader

AIR 20.0.0.233 URLMonitor broken with iOS 9 ?

Translate