Search code examples
androidactionscript-3flashair

Flash AIR 3.2 Android Captive Runtime URLLoader throws stream error #2032 local file


The following code is a snippet of a much larger project I'm working on. The problem is when I test the app in Flash CS6 urlLoader reads 25Notes.txt perfectly but when I try debugging the app (via Flash's built in "Debug>Debug Movie>On Device via USB") on my Android device (HTC Incredible) urlLoader throws a stream error #2032.

I'm deploying the app with Captive Runtime from AIR 3.2 using Flash CS6 and my project is organized with no extraneous files or folders.

Please let me know if you have any insight or suggestions and if you need more of an explanation or code.

I'm also not sure if Captive Runtime in Flash CS6 packages all of the local files in the root project folder or just the ones used in the app or none at all. Any information about this would be greatly appreciated as well.

    var FILE_LIST_PATH:String = "/25Notes/25Notes.txt";
var mp3List:Array = new Array();

LoadFile();

function LoadFile()
{
    var urlRequest:URLRequest = new URLRequest(FILE_LIST_PATH);
    var urlLoader:URLLoader = new URLLoader();

    urlLoader.addEventListener(Event.COMPLETE, processTextFile);
    urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    urlLoader.load(urlRequest);
}

function onIOError(e:IOErrorEvent){
    trace("can't load file list:   " + e);
}


function processTextFile(event:Event):void
{
    var loader:URLLoader = URLLoader(event.target);
    var textFile:String = loader.data;
    mp3List = textFile.split("\n");
    for (i=0;i<mp3List.length;i++){
        trace(mp3List[i],i);
    }
}

Here's what the IOError trace returns:

can't load file list:   [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: app:/25Notes/25Notes.txt" errorID=2032]

I'm totally stumped. Please help!!


Solution

  • Is the file being saved by the app at runtime and you are trying to retrieve it? If not, that URL is incorrect. The app:/ directory is the applicationStorageDirectory on the device, not a location within the app itself. You'll need to embed your txt file as a Class and access it that way

    [Embed(source="assets/ui/images/phone/menu-myvideos-active-160.png")]
    var MyVideosActive160:Class;
    

    That is something from a project I am actually working on finishing right now. That embeds an image and allows me to access it afterward. To access it, I simply do

    var bmp:Bitmap = new MyVideosActive160();
    

    If you don't embed, I don't believe you can actually access the file. Every file that needs to be included within the app must be embedded.

    If you are saving the file at run time at some point, you'll want to do it this way

    var path:String = new File(new File.applicationStorageDirectory.resolvePath("/25Notes/25Notes.txt").nativePath).url;
    

    That will output a file:/// URL, rather than a url using app:/. I am using this method to play downloaded videos in my app. It's a crappy workaround that Adobe should have built into SDK, but that's what we have to deal with.