1

I need to write a ByteArray to a file on local disk with Flash AS3. The flashapplication is run locally (it's a projector exe).

I found the FileReference class with the save() function which works perfect. The only problem is, that this function opens a filebrowser and let's the user select where to store the file. However - i have the path already as string and need to save to this location without useraction (since i'm exporting a lot of files into this directory in one go and don't want the user to choose each one manually).

Is there a way to store a bytearray from a projector to local disk without opening a filebrowser?

I'm also using mdm Zinc, which actually provides a function to save a ByteArray to disk, but this function is for some unknown reasons not working. I already filed a bugreport, but I need to get this to work very urgently, so i'm looking for alternatives!

Thanks!

khael
  • 2,600
  • 1
  • 15
  • 36
genesys
  • 41
  • 2
  • 5

2 Answers2

7

Noting that you are running your application as an .exe I assume you are using some variant of AIR, and have a security permission to access the filesystem. You should take a look at the FileStream class. Here is a very simple example of how I used it to write a ByteArray to a hard-coded file location.

var fs : FileStream = new FileStream();
var targetFile : File = File.desktopDirectory.resolvePath("test.raw");
fs.open(targetFile, FileMode.WRITE);
fs.writeBytes(myByteArray,0,myByteArray.length);
fs.close();
glastonbridge
  • 707
  • 6
  • 5
1

If all you need is persistence (you read what you write), you can take a look at SharedObject.

Mihai Nita
  • 5,547
  • 27
  • 27
  • no i actually need to write to disk. The tool shall export jpg files which are auto generated in the application (i have them as ByteArray data, but i need to write them to disk at specific locations). And it should be possible without using AIR – genesys Nov 17 '09 at 09:05
  • Then the answer is: no, not possible without AIR and without a dialog asking for user's permission. Imagine if that would be possible: any random web site would be able to store 400 GB of data on your disk. – Mihai Nita Nov 18 '09 at 07:48