是否可以使用 AS3 或 AIR 创建纯文本文件?
例如:我想创建一个名为“MyTextFile.txt”的纯文本文件,让它包含“这是我的文本文件”的文本。并将其保存到我的桌面。
另一种选择是让文件已经存在于目录中,所以我只需要重写它的内容 - 假设这会更容易。
所有这些都应该作为后台进程发生,不会出现任何保存对话框面板。
是否可以使用 AS3 或 AIR 创建纯文本文件?
例如:我想创建一个名为“MyTextFile.txt”的纯文本文件,让它包含“这是我的文本文件”的文本。并将其保存到我的桌面。
另一种选择是让文件已经存在于目录中,所以我只需要重写它的内容 - 假设这会更容易。
所有这些都应该作为后台进程发生,不会出现任何保存对话框面板。
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();
我知道这是一篇旧文章,但考虑以下从输入文本字段的文本创建一个新的 .txt 文件。
var tf:TextField;
var fileRef:FileReference;
function saveFile(evt):void
{
fileRef = new FileReference();
fileRef.save(tf.text, "saveFile.txt");
}
还要考虑这段文字:
在移动设备上运行时,您看不到跟踪语句的输出。
函数 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;
}
等等……