views:

1659

answers:

4

Hi,

How do i open file and get its content as a ByteArray in AS3. I saw examples, using FileStream & File classes from flex.filesystem, but the doc says it's for AIR only.

Thanks,

Nava

+2  A: 

You can try either URLLoader with content set for binary, or use URLStream. What do you need to load ?

George Profenza
Thanks for reply. I need to load local binary data file
Nava Carmon
no problem. an urlloader shouuld do: var binLoader:URLLoader = new URLLoader();binLoader.dataFormat = URLLoaderDataFormat.BINARY;binLoader.addEventListener(Event.COMPLETE, binLoaded);binLoader.load(new URLRequest('yourfile.bin'));
George Profenza
I think it was my fault, that the code didn't work. I couldn't find the file, since i didn't put it near Main.mxml, rather near the code source...
Nava Carmon
A: 

Flex security prevents simple access to local files.

The most commonly used workaround is having the user select a file, send that to your server, and then downloading that file from your server.

There is access to some local storage (using SharedObject) for storing and reading settings.

hth,

Koen

Koen Weyn
I really need this to be local. Is that such a big deal to open a local file on flex? May be it should be an archive?
Nava Carmon
If you're only using local files, you can set the compiler to use a local file security policy by adding -use-network=false as a compiler argument in compiler settings. goodluck!
George Profenza
+1  A: 

You can use a FileReference object to browse for a file and then access the raw bytes via the "data" property on the FileReference when the "complete" event is dispatched.

Christophe Herreman
A: 

New feature in Flash 10. Last time you can't read the file directly. But now, you can. http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/

5566