How to autosave (without dialog box) an image using as3 (Flash CS5)

Alon picture Alon · May 13, 2011 · Viewed 8.2k times · Source

It looks like an easy question but I can't find the answer.

I have this code:

import com.adobe.images.PNGEncoder;
var fr:FileReference = new FileReference();

var pngSource:BitmapData = new BitmapData (stage.width, stage.height);
pngSource.draw(sketch_mc);

var ba:ByteArray = PNGEncoder.encode(pngSource);
fr.save(ba,'alon20.png');

which saves me an image. I want it to autosave it and not to open a dialog box as it does now. the reason I want that to happen is because I want to take picture of every frame in render time (to make a movie out of it).

What am I missing?

Answer

Simon Eyraud picture Simon Eyraud · May 13, 2011

In pure flash, you can't save a file without a dialogbox. However, if it's a desktop app, you use Air :

var fs : FileStream = new FileStream();
var targetFile : File = File.desktopDirectory.resolvePath('alon20.png');
fs.open(targetFile, FileMode.WRITE);
fs.writeBytes(ba);
fs.close();