How can you save out a String into a file in AS3?

 picture · Aug 5, 2009 · Viewed 16.6k times · Source

I have a string the user has typed and I want to save it into a file on the users harddrive. Can you do that? And if so, how?

Answer

Clox picture Clox · Aug 5, 2009

Yes you can, with FileReference. This is basically how it's done:

var bytes:ByteArray = new ByteArray();
var fileRef:FileReference=new FileReference();
fileRef.save("fileContent", "fileName");

Doesn't look too hard, does it? And here's a video-tutorial on it too:

http://www.gotoandlearn.com/play?id=76

And the documentation:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

Hope that helps.