Search code examples
apache-flexflashactionscript-3filereference

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


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?


Solution

  • 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.