如何“强行下载”完全在Flash中生成的文件?

时间:2022-07-16 04:52:59

If I'm generating a binary file inside Flash Player, how do I pop up a 'Save' dialog for the file without sending it up the the server first?

如果我在Flash Player中生成二进制文件,如何在不首先将其发送到服务器的情况下弹出文件的“保存”对话框?

I'm sure I heard this was a new feature in Flash 10.

我确信我听说这是Flash 10中的一项新功能。

Cheers,
James

2 个解决方案

#1


This will help, and really show you how to do it, all you have to keep in mind is that opening and saving files can only be done with user initiation, it cannot be automated, so not sure what you are trying to do, but this will help:

这将有所帮助,并且真正告诉你如何做到这一点,你必须要记住的是,打开和保存文件只能通过用户启动来完成,它不能自动化,所以不确定你要做什么,但是这将有助于:

http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/

#2


If you are inside the flash player, you can do the following:

如果您在Flash播放器中,则可以执行以下操作:

import flash.net.FileReference;
import flash.utils.ByteArray;

var fileReference:FileReference = new FileReference();

var data:ByteArray; // load up your data into this ByteArray

fileReference.save(data, "outputfile.dat");

This will not work if you are running in the browser-- at least as far as I remember, but if you are in the flash player this will work.

如果你在浏览器中运行,这将无法工作 - 至少就我记忆而言,但如果你在Flash播放器中,这将有效。

The FileReference.save() method will popup a dialog for the user to choose where to save the file, so the filename given is just a suggested filename.

FileReference.save()方法将弹出一个对话框,供用户选择保存文件的位置,因此给出的文件名只是建议的文件名。

Edit: See Technomaag's comment below also if you're having problems

编辑:如果您遇到问题,请参阅下面的Technomaag评论

#1


This will help, and really show you how to do it, all you have to keep in mind is that opening and saving files can only be done with user initiation, it cannot be automated, so not sure what you are trying to do, but this will help:

这将有所帮助,并且真正告诉你如何做到这一点,你必须要记住的是,打开和保存文件只能通过用户启动来完成,它不能自动化,所以不确定你要做什么,但是这将有助于:

http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/

#2


If you are inside the flash player, you can do the following:

如果您在Flash播放器中,则可以执行以下操作:

import flash.net.FileReference;
import flash.utils.ByteArray;

var fileReference:FileReference = new FileReference();

var data:ByteArray; // load up your data into this ByteArray

fileReference.save(data, "outputfile.dat");

This will not work if you are running in the browser-- at least as far as I remember, but if you are in the flash player this will work.

如果你在浏览器中运行,这将无法工作 - 至少就我记忆而言,但如果你在Flash播放器中,这将有效。

The FileReference.save() method will popup a dialog for the user to choose where to save the file, so the filename given is just a suggested filename.

FileReference.save()方法将弹出一个对话框,供用户选择保存文件的位置,因此给出的文件名只是建议的文件名。

Edit: See Technomaag's comment below also if you're having problems

编辑:如果您遇到问题,请参阅下面的Technomaag评论