如何在不询问as3的情况下写外部文件 [英] how to write on external file without ask in as3

查看:86
本文介绍了如何在不询问as3的情况下写外部文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

var fileRef:FileReference = new FileReference();
fileRef.save("ciao coso","lingua.txt");

写入现有的lingua.txt文件. 该脚本有效,但是每次他保存时都会问我将文件保存在哪里...有一种方法可以自动保存在现有的lingua.txt文件中? 对不起,英语不好,我是意大利人. 也许我必须使用其他技术?

to write on an existing lingua.txt file. the script works but every time he save ask me where to save the file... there is a way to save automatically on the existing lingua.txt file? sorry for bad english, i'm italian. maybe I have to use a different technique?

推荐答案

您无法在Flash Player中写入用户的文件系统.出于安全原因,用户必须是保存文件的用户.当Flash在网络浏览器中运行时,这是一件非常好的事情.

You cannot write to the user's file system in Flash Player; for security reasons, the user has to be the one saving the file. This is a very good thing when flash is running in a web browser.

不过,您可以使用 SharedObjects -在行为上类似于cookie(永久存储不依赖).

As a workaround though, you can use SharedObjects - which are cookie like in their behavior (not to be relied upon for persistent storage).

现在,如果您使用的是Adobe AIR,则无需用户输入即可保存文件.

Now, if you're using Adobe AIR, you can save files with no user input.

您可以使用 File FileStream 类:

//do these 3 lines regardless of opening/saving
var file:File = File.applicationStorageDirectory; //default place to save files - see the File class documentation for other shortcuts to common places
file = file.resolvePath("lingua.txt");
var fileStream:FileStream = new FileStream();

//to open the file:
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readUTF();
fileStream.close();

//to save the file:
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTF("my string to write");
fileStream.close();

有关写入文件的更多信息,请参见本文 :

For more info on writing files, see this article:

这篇关于如何在不询问as3的情况下写外部文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆