Highlighted

Download assests from internet in Air for IOS

Participant ,
Sep 28, 2016

Copy link to clipboard

Copied

Dear Friends,

Iam developing an eLearning app. As app store will allow to upload only 4GB sized apps. All my lessons size are heavy, so I planned to create only app, Then down load the lessons and assets from internet on first time opening the app. How can I do this please help me to do this. I am new for this kind of app (app using resource from internet). I am using Air for IOS.

Thanks in advance,

Regards,

Syed Abdul Rahim

TOPICS
Development

Views

776

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Download assests from internet in Air for IOS

Participant ,
Sep 28, 2016

Copy link to clipboard

Copied

Dear Friends,

Iam developing an eLearning app. As app store will allow to upload only 4GB sized apps. All my lessons size are heavy, so I planned to create only app, Then down load the lessons and assets from internet on first time opening the app. How can I do this please help me to do this. I am new for this kind of app (app using resource from internet). I am using Air for IOS.

Thanks in advance,

Regards,

Syed Abdul Rahim

TOPICS
Development

Views

777

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Sep 28, 2016 0
Participant ,
Sep 29, 2016

Copy link to clipboard

Copied

I want to download assets from internet and copy to a particular location (document directory or application directory) of IPAD. Pls help me friends... is there a way? how can I do this?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Sep 29, 2016 0
Participant ,
Oct 03, 2016

Copy link to clipboard

Copied

Dear Friends,

iam using the following code to copy from internet and loading in IPAD.

import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.net.FileReference;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.utils.ByteArray;
import flash.display.Loader;
import flash.system.LoaderContext;
import flash.system.ApplicationDomain;

var file_url: String = "";
var lc: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
var ldr: Loader = new Loader();

DownloadFileMobileAS3();
function DownloadFileMobileAS3() {
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
createLoader();
}
function createLoader(): void {
// TODO Auto-generated method stub
var urlLoader: URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, complete_handler);
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(new URLRequest("http://www.abc.com/test.swf"));
}

function complete_handler(event: Event): void {
var data: ByteArray = event.target.data;
var fileStream: FileStream = new FileStream();
fileStream.addEventListener(Event.CLOSE, fileWritten);
trace("something copied...");
txt.text = "something copied...";
fileStream.open(new File(File.documentsDirectory.nativePath + "\\test.swf"), FileMode.WRITE);

file_url = File.documentsDirectory.nativePath +"\\test.swf";

fileStream.writeBytes(data, 0, data.length);
fileStream.close();
load_file();
}

function fileWritten(e: Event): void {
trace("File Saved to Desktop");
}

function load_file() {
ldr = new Loader();
var req: URLRequest = new URLRequest(file_url);
ldr.load(req, lc);
//ldr.load(req);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loading_finished);
}

function loading_finished(event: Event) {
trace("loading finished");
addChild(ldr);
}

All are working fine in computers, when I install in IPAD its not working. pls check and answere me if iam missing some....

Thanks and Regards,

Syed Abdul Rahim

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 03, 2016 0
Adobe Employee ,
Oct 05, 2016

Copy link to clipboard

Copied

Hi Syed,

Try using File.cacheDirectory.resolvePath(fileURL); instead of document directory.

If we try to write a file using File. applicationDirectory, That is a read-only directory on iOS (and normally other platforms as well, as mentioned in the docs for File: File - Adobe ActionScript® 3 (AS3 ) API Reference  )

You shouldn't ever try to write into File.applicationDirectory you should at least use File.applicationStorageDirectory, and if you need cache content consider using File.cacheDirectory. All those helper static File.

  • Directory properties do all the work for you to chose the right folder no matter what platform.
  • If you are curious where those directories resolve on various platforms there is a nice summary here:

    Adobe Flash Platform * Working with File objects in AIR

    Thanks,

    Adobe AIR Team

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 05, 2016 1
    Participant ,
    Oct 06, 2016

    Copy link to clipboard

    Copied

    Dear Mr.Deesharm/ankit,

    Greetings! thks for the help. Now its copied in to the IPad. and giving confirmation.. but it is not loading it give 2035 error.. that is url not found.. pls check my code and advice me why it is not loading when click on the button bt1. My code is as follows:

    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.filesystem.File;
    import flash.filesystem.FileMode;
    import flash.filesystem.FileStream;
    import flash.net.FileReference;
    import flash.net.URLLoader;
    import flash.net.URLLoaderDataFormat;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import flash.display.Loader;
    import flash.system.LoaderContext;
    import flash.system.ApplicationDomain;

    var file_url: String = "";
    var lc: LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain, null);
    var fs: FileStream = new FileStream();

    var ldr: Loader = new Loader();

    DownloadFileMobileAS3();
    function DownloadFileMobileAS3() {
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    createLoader();
    }
    function createLoader(): void {
    var urlLoader: URLLoader = new URLLoader();
    urlLoader.addEventListener(Event.COMPLETE, complete_handler);
    urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
    urlLoader.load(new URLRequest("http://www.abc.com/test.swf"));
    }

    function complete_handler(event: Event): void {
    var data: ByteArray = event.target.data;
    txt.text = String(data);

    var fileStream: FileStream = new FileStream();
    fileStream.addEventListener(Event.CLOSE, fileWritten);
    trace("something copied...");
    txt.text = "something copied...";
    fileStream.open(File.applicationStorageDirectory.resolvePath("swf/test.swf"), FileMode.WRITE);

    file_url = File.applicationStorageDirectory.resolvePath("swf/test.swf").nativePath
    fileStream.writeBytes(data, 0, data.length);
    fileStream.close();
    //load_file();
    txt.text = "something copied... " + File.applicationStorageDirectory.resolvePath("swf/test.swf").exists;
    }

    function fileWritten(e: Event): void {
    trace("File Saved to Desktop");
    }

    import flash.events.MouseEvent;
    bt1.addEventListener(MouseEvent.CLICK, load_file);
    function load_file(event: MouseEvent) {
    txt.appendText(" " + file_url + " loading Started ");
    ldr = new Loader();
    var req: URLRequest = new URLRequest(file_url);
    txt.appendText(" " +req.url);
    req.cacheResponse = false;
    req.useCache = false;
    ldr.load(req, lc);
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loading_finished);

    }

    function loading_finished(event: Event) {
    trace("loading finished");
    txt.appendText(" " + file_url + " loading Finished");
    addChild(ldr);
    }

    Thanks and Regards,

    Syed Abdul Rahim

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 06, 2016 0
    Participant ,
    Oct 06, 2016

    Copy link to clipboard

    Copied

    hi for ur info... files loading in computer.. but not in IPAD...

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 06, 2016 0
    Adobe Employee ,
    Oct 06, 2016

    Copy link to clipboard

    Copied

    Hi Syed,

    Have you tried using

    fileStream.open(File.cacheDirectory.resolvePath("swf/test.swf"), FileMode.WRITE);

    file_url = File.cacheDirectory.resolvePath("swf/test.swf").nativePath

    instead of

    file_url = File.applicationStorageDirectory.resolvePath("swf/test.swf").nativePath in your application code ?

    Thanks,

    Adobe AIR Team

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 06, 2016 0
    Participant ,
    Oct 06, 2016

    Copy link to clipboard

    Copied

    HI deesharm,

    I tried with applicationStorageDirectory its loading now but it is giving one error, security sandbox. Same like below:

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

    at flash.display::Stage/requireOwnerPermissions()

    at flash.display::Stage/addEventListener()

    at b777_hz_pt_cs_efb_opt_f12_fla::slider_26/PointerDrag()

    For loading what I have modified was :

    file_url = File.applicationStorageDirectory.resolvePath("swf/test.swf").url;

    its loading fine in IPad, but iam getting security Sanbox violation, what might be the reason I don't know... pls help me to solve this.

    Thanks and Regards,

    Syed Abdul Rahim

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 06, 2016 0
    Adobe Employee ,
    Oct 06, 2016

    Copy link to clipboard

    Copied

    Hi Syed,

    If two SWF files are served from different domains — for example, http://siteA.com/swfA.swf and http://siteB.com/siteB.swf — then, by default, AIR does not allow swfA.swf to script swfB.swf, nor swfB.swf to script swfA.swf. A SWF file gives permission to SWF files from other domains by calling Security.allowDomain(). This is called cross-domain scripting. By calling Security.allowDomain("siteA.com"), siteB.swf gives siteA.swf permission to script it.

    Please refer to below link:

    Security - Adobe ActionScript® 3 (AS3 ) API Reference

    Thanks,

    Adobe AIR Team

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 06, 2016 0
    Participant ,
    Oct 17, 2016

    Copy link to clipboard

    Copied

    Hi deesharm,

    Greetings! I have checked with dummy swf files with script. when we use "URLLoaderDataFormat.BINARY" and "ByteArray" to download files from internet, IOS is not allowing to write AS3 script. its writing only picture and animations.. its not writing script. In windows its download and write with AS script.

    please advice me is thee any other way to download files from internet using Air for IOS? pls

    Thanks in advance,

    Regards,

    Syed Abdul Rahim

    Likes

    Translate

    Translate

    Report

    Report
    Community Guidelines
    Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
    Reply
    Loading...
    Oct 17, 2016 0