Flash 在 Windows 中保存,而不是在 Linux 中,FileReference.save()
下面的代码在 Fedora 15 上的 Flex 4 SDK 上可以正常编译。单击鼠标打开对话框,单击“确定”,然后保存一个文件,但该文件是空的。我在 Windows 计算机上运行相同的 SWF 文件(在 Linux 计算机上编译),并且创建的文件包含预期的数据。
然后我将 FileReference 声明从函数中分解到类级别,希望避免 一个已知错误,但同样的问题仍然存在。
为了找到解决方法,我将调试 Flash 播放器添加到我的路径中,并在没有浏览器的情况下从 Flash 运行该文件,并且它有效。所以现在 Flex 问题已经变成了 Firefox 问题,可能是由于 我用来安装插件的可疑过程,但没有真正了解发生了什么。我正在运行 Firefox 5.0。
本质上我的工作流程是固定的,但也许执行上述操作的人将无法使用 FileReference.save() 的项目?我应该担心这种边缘情况吗?
/*
WriteTheFile.as
Original code by Brian Hodge ([email protected])
Test to see if ActionScript/Flash can write files
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
public class WriteTheFile extends Sprite
{
private var _xml:String;
private var fr:FileReference;
public function WriteTheFile():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
}
private function _onMouseDown(e:MouseEvent):void
{
fr = new FileReference()
fr.save("<xml><test>data</test></xml>", "filename.txt");
}
}
}
编辑:缺少一行,已在上面修复
编辑:在上面的代码中解决了答案,但存在相同的问题。
编辑:当调用独立播放器时,这适用于同一系统。因此这是一个浏览器(FF 5.0)插件问题。
The code below compiles fine on the Flex 4 SDK on Fedora 15. Mouse-click opens the dialog box, I click okay, and a file is saved, but the file is empty. I run the same SWF file (that was compiled on the Linux machine) on a Windows machine, and the created file contains the expected data.
Then I broke the FileReference declaration out of the function into the class level, hoping to avoid a known bug, but the same problem persists.
Hoping to set up a workaround, I added the debug Flash player to my path and ran the file from Flash without the benefit of the browser, and it works. So now a Flex problem has become a Firefox problem, maybe owing to a shady procedure I used to install the plugin without really understanding what was happening. I am running Firefox 5.0.
In essence my workflow is fixed, but perhaps people who performed the above will not be able to use projects with FileReference.save()? Should I be worried about this edge case?
/*
WriteTheFile.as
Original code by Brian Hodge ([email protected])
Test to see if ActionScript/Flash can write files
*/
package{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.ByteArray;
import flash.net.FileReference;
public class WriteTheFile extends Sprite
{
private var _xml:String;
private var fr:FileReference;
public function WriteTheFile():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
//Calling the save method requires user interaction and Flash Player 10
stage.addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
}
private function _onMouseDown(e:MouseEvent):void
{
fr = new FileReference()
fr.save("<xml><test>data</test></xml>", "filename.txt");
}
}
}
EDIT: was missing a line, fixed above
EDIT: addressed answer in code above, but the same problem exists.
EDIT: This works on the same system when the standalone player is invoked. Therefore this is a browser (FF 5.0) plugin problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将行
var fr:FileReference = new FileReference();
放在类级别(函数外部)。显然这是一个已知的错误:
http://www .techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/
Try putting the line
var fr:FileReference = new FileReference();
at class level (outside the function). Apparently this is a known bug:
http://www.techper.net/2007/12/30/flash-filereferencebrowse-problems-on-linux/