as3 android saving downloaded files from server

The following code WORKS when run on the Desktop but does not on the android device. I am thinking it has something to do with the FileStream below.

Any thoughts on how I can save this to an Android device too?

import flash.display.MovieClip;
import flash.display.Sprite;

import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, complete_handler);
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load(new URLRequest(""));
//any file type;

function complete_handler(event:Event):void
    var data:ByteArray =;

    var fr:FileReference = new FileReference();
    trace(File.applicationDirectory.nativePath);, 'Catholic.mp3');

    var fileStream:FileStream = new FileStream();
    trace(File.applicationDirectory.nativePath); File (File.applicationStorageDirectory.nativePath+"\\Catholic.mp3"),FileMode.WRITE);
    fileStream.writeBytes(data, 0, data.length);


    Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.
    at Untitled_fla::MainTimeline/complete_handler()[Untitled_fla.MainTimeline::frame1:25]

THIS IS THE LINE IT'S REFERRING TOO: File (File.applicationStorageDirectory.nativePath+"\\Catholic.mp3"),FileMode.WRITE);


It works with Air for Android. Yes you can do more with it later but this is the basic start.


/// It can be an mp3,jpg, png, etc... just change the url
/// and the extension name. nice huh?
var yourFileLocation = "";
var yourFileName = "YourSong.mp3";

var daFile:FileReference = new FileReference(); URLRequest(yourFileLocation), yourFileName);

I worked FOREVER... to find this. I hope it helps many. Why is this not more common knowledge? Somethings in action-script are impossible to find sometimes.

There is ONE question I have regarding this. How can I make the code download directly to a location on the device rather than the user having to choose the location. Thanks Much!

Need Your Help

Read a record selected in DataGridView table and read through info of that record into fields that is not shown in the table

c# winforms visual-studio datagridview .net-3.5

Note: Some of the code included below has already been used in some of my other questions but regarding other issues. I have also edited most of the post to cause less confusion!

Fluent NHibernate memory leak

nhibernate memory-leaks fluent-nhibernate

I'm pulling my hair over what seems to be a memory leak but I cannot find the cause :(