如何使用as3(Flash CS5)自动保存(不使用对话框)图像

时间:2011-05-13 10:21:03

标签: flash actionscript-3 autosave printscreen

这看起来很简单,但我找不到答案。

我有这段代码:

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');

为我保存了一张图片。我想要自动保存它,而不是像现在一样打开一个对话框。我希望这种情况发生的原因是因为我想在渲染时间拍摄每一帧(用它制作一部电影)。

我错过了什么?

1 个答案:

答案 0 :(得分:12)

在纯闪存中,如果没有对话框,则无法保存文件。但是,如果它是桌面应用程序,则使用Air:

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