AS3 / AIR - 创建纯文本文件?

发布于 2024-09-25 14:00:19 字数 194 浏览 12 评论 0原文

是否可以使用 AS3 或 AIR 创建纯文本文件?

示例:我想创建一个名为“MyTextFile.txt”的纯文本文件,让它包含“这是我的文本文件”的文本。并将其保存到我的桌面。

另一种选择是让文件已经存在于目录中,所以我只需要重写它的内容 - 假设这样会更容易。

所有这些都应该作为后台进程发生,而不出现任何保存对话框面板。

is it possible to create a plain text file with AS3 or AIR?

example: i would like to create a plain text file named "MyTextFile.txt", have it contain text that reads "This is my text file." and save it to my desktop.

another option would be to have the file already exist in a directory, so i would only have to rewrite its contents - assuming that would be easier.

all of which should happen as a background process, without any save dialoge panel appearing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

悍妇囚夫 2024-10-02 14:00:19
var file:File = File.desktopDirectory.resolvePath("MyTextFile.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("This is my text file.");
stream.close();
var file:File = File.desktopDirectory.resolvePath("MyTextFile.txt");
var stream:FileStream = new FileStream();
stream.open(file, FileMode.WRITE);
stream.writeUTFBytes("This is my text file.");
stream.close();
成熟的代价 2024-10-02 14:00:19

我知道这是一篇旧文章,但请考虑以下内容,从输入文本字段的文本创建新的 .txt 文件。

var tf:TextField;
var fileRef:FileReference;

function saveFile(evt):void
{
fileRef = new FileReference();
fileRef.save(tf.text, "saveFile.txt");
}

I know this is an old post, but consider the following to create a new .txt file from an input text field's text.

var tf:TextField;
var fileRef:FileReference;

function saveFile(evt):void
{
fileRef = new FileReference();
fileRef.save(tf.text, "saveFile.txt");
}
記柔刀 2024-10-02 14:00:19

另请考虑以下文本:

文本字段而不是跟踪语句

在移动设备上运行时,您无法看到跟踪语句的输出。

函数 createTracingTextField(x:数字, y:数字,
宽度:数字,高度:数字):TextField {

var tracingTF:TextField = new TextField(); 
tracingTF.x = x; 
tracingTF.y = y; 
tracingTF.width = width; 
tracingTF.height = height; 

// A border lets you more easily see the area the text field covers. 
tracingTF.border = true; 
// Left justifying means that the right side of the text field is automatically 
// resized if a line of text is wider than the width of the text field. 
// The bottom is also automatically resized if the number of lines of text 
// exceed the length of the text field. 
tracingTF.autoSize = TextFieldAutoSize.LEFT; 

// Use a text size that works well on the device. 
var myFormat:TextFormat = new TextFormat(); 
myFormat.size = 18; 
tracingTF.defaultTextFormat = myFormat; 

addChild(tracingTF); 
return tracingTF; 

}

等等...

Also consider this text:

Text fields instead of trace statements

When running on a mobile device, you cannot see the output from the trace statements.

function createTracingTextField(x:Number, y:Number,
width:Number, height:Number):TextField {

var tracingTF:TextField = new TextField(); 
tracingTF.x = x; 
tracingTF.y = y; 
tracingTF.width = width; 
tracingTF.height = height; 

// A border lets you more easily see the area the text field covers. 
tracingTF.border = true; 
// Left justifying means that the right side of the text field is automatically 
// resized if a line of text is wider than the width of the text field. 
// The bottom is also automatically resized if the number of lines of text 
// exceed the length of the text field. 
tracingTF.autoSize = TextFieldAutoSize.LEFT; 

// Use a text size that works well on the device. 
var myFormat:TextFormat = new TextFormat(); 
myFormat.size = 18; 
tracingTF.defaultTextFormat = myFormat; 

addChild(tracingTF); 
return tracingTF; 

}

And so forth...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文