0

I have to browse for and open a file in AIR. I can access the file via the File class:

var file:File = File.applicationStorageDirectory.resolvePath("somefile.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);

And I can browse for a file via the FileReference class:

var fileRef:FileReference = new FileReference();
fileRef.browse(allTypes);

But I cannot seem to get the file from the FileReference object into the File object.

There is no "path" member exposed when debugging the FileReference after opening it, any ideas?

1 Answer 1

1

You'll have to use File#browseForOpen() instead of FileReference#browse(), something like this:

private var f:File;

public function browseForRead():void {
    f = File.documentsDirectory;
    f.addEventListener(Event.SELECT, readFile); 
    f.browseForOpen("Open file");
}

private function readFile(event:Event):void {
    var stream:FileStream = new FileStream();
    stream.open(f, FileMode.READ);
    trace(stream.readUTFBytes(stream.bytesAvailable));
}

FileReference#browse() is used for uploading files in web applications.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for spotting the typo @lukevanin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.