Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AS3 / AIR - Creating a plain text file?

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.

like image 468
Chunky Chunk Avatar asked Sep 29 '10 15:09

Chunky Chunk


2 Answers

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();
like image 177
Claus Wahlers Avatar answered Sep 27 '22 21:09

Claus Wahlers


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");
}
like image 23
Luke Avatar answered Sep 27 '22 20:09

Luke