2011-05-13 34 views
3

它看起來像一個簡單的問題,但我找不到答案。如何使用as3自動保存(沒有對話框)圖像(Flash CS5)

我有這樣的代碼:

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

從而節省了我的圖像。我希望它能夠自動保存而不是像現在這樣打開一個對話框。我希望這種情況發生的原因是因爲我想在渲染時間內拍攝每一幀圖片(以製作一部電影)。

我錯過了什麼?

回答

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