Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top