Ответ 1
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();
Можно ли создать простой текстовый файл с AS3 или AIR?
example: я хотел бы создать простой текстовый файл с именем "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");
}
Также рассмотрим этот текст:
Текстовые поля вместо операторов трассировки
При работе на мобильном устройстве вы не можете видеть вывод из операторов трассировки.
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;
}
И так далее...