AS3 FileReference.save() 在本地测试时有效,但在浏览器中无效
我创建了一个绘画应用程序,当用户想要保存他的绘图时,他只需点击保存按钮,就会弹出一个对话框 - 或者应该这样做。
在开发机器上本地测试时没有问题,但每当应用程序加载到浏览器中时,它就无法工作。即使我在浏览器中加载本地 SWF 文件,它也无法工作。
下面的代码是我用来保存文件的代码,正如所说的那样,它在本地工作正常,但每当它进入浏览器时,它就无法工作。保存对话框根本不会弹出。
有什么建议吗?
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');
运行 FlashPlayer 11 并编译为 10.2 BTW。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个安全问题。现在只能通过直接用户事件(例如单击)打开保存文件对话框窗口。一种解决方案是在创建图像时通知用户,并询问他是否要将文件保存在本地。如果他单击“是”,您将调用 save 方法。
以下是有关此更改的更多信息:
http://www.bogdanmanate。 com/2010/05/12/flex-error-2176-when-using-filereference/
希望这有帮助。祝你有美好的一天。
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.