Search code examples
actionscript-3filememoryloadfilereference

Is it possible to access raw file data as FileReference.load() loads it in memory?


I think it's not, but maybe I'm wrong. Anyone?

UPDATE:

It's not.


Solution

  • i think you can, at least there is nothing in the docs that states otherwise. try adding a ProgressEvent on the FileReference object to read it's data (ByteArray) property after calling load().

    however, if you're loading a file with URLLoader, a URLLoader's data property is only populated once the load operation has completed.


    [EDIT]

    so it's, after all, not possible to access live fileReference data while loading. the docs should explicitly state that it's not possible since it's a valid request.

    however, after a some stumbling thru the docs i realized that you can do this by using the URLStream class, which provides methods to read data while it's loading - it's designed to do exactly what you are looking for.

    the only catch, in this case, is that URLStream requires a full URL path (URLRequest object), which is not obtainable with FileReference for security reasons - it's only possible to get the name of a selected file, not the complete path. obtaining a local file path in AIR is very easy, but since you want your application to be browser-resistant i'm not quite sure how you'll be able to access file paths from the user's computer - unless they type in the file path, but requiring your users to do so would seriously degrade UX.