AS3 FileReference.save() works when testing locally but not in the browser

浪尽此生 提交于 2019-12-24 12:51:33

问题


I have created a painting app and when the user want's to save his drawing he simply hits the save button and a dialog pops up - or should do.

When testing locally on dev machine it's no problem but whenever the app is loaded in a browser it won't work. Even if I load the local SWF file in a browser it won't work.

The following code is what I use to save the file and as said it works fine locally but whenever it goes into a browser it dosen't.The save dialog simply never pops up.

Any suggestions?

var bitmapData:BitmapData = new BitmapData(canvas.width, canvas.height);
bitmapData.draw(canvas);
var jpg:JPEGEncoder = new JPEGEncoder(100);
var ba:ByteArray = jpg.encode(bitmapData);

file = new FileReference();
file.addEventListener(Event.COMPLETE, fileSaveComplete);
file.addEventListener(IOErrorEvent.IO_ERROR, error);
file.save(ba, 'FileName.jpg');

Running FlashPlayer 11 and compiling to 10.2 BTW.


回答1:


That is a security issue. A save file dialog window can now only be opened as a result to a direct user event, like a click. One solution is to notify the user when the image is created, and ask if he wants to save the file locally. And if he clicks yes, you call the save method.

Here's more info on this change:

http://www.bogdanmanate.com/2010/05/12/flex-error-2176-when-using-filereference/

Hope this helps. Have a good day.



来源:https://stackoverflow.com/questions/9293648/as3-filereference-save-works-when-testing-locally-but-not-in-the-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!