Reputation: 7285
I have a bit of code that I want to change to make it save to the application directory. (the directory the application is installed at).
While currently the bit of code I have works it just brings up a browse window for me to pick where to save the file. I want it to default to the application directory though.
How do I change it to do just that.
function save(e:Event):void {
var fileRef:FileReference;
fileRef = new FileReference();
fileRef.save(addfriends.text, "friends.txt");
}
Upvotes: 0
Views: 7999
Reputation: 3851
This should write info.txt (or jpg commented out) to the applications document directory.
//f = File.documentsDirectory.resolvePath("logo.jpg");
f = File.documentsDirectory.resolvePath("text.txt");
stream = new FileStream();
stream.open(f, FileMode.WRITE);
//var j:JPGEncoder = new JPGEncoder(80);
//var bytes:ByteArray = j.encode(visualLogo.bitmapData);
//stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.writeUTFBytes("This is my text file.");
stream.close();
Note that it needs testing on the device, not on your Mac/PC.
Alternatively, check out Save encoded .mp3 to applicationStorageDirectory Adobe Air iOS
Upvotes: 0
Reputation: 4708
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html
The FileReference and FileReferenceList classes do not let you set the default file location for the dialog box that the browse() or download() methods generate. The default location shown in the dialog box is the most recently browsed folder, if that location can be determined, or the desktop.
Another thing:
Note: In Adobe AIR, the File class, which extends the FileReference class, provides more capabilities and has less security restrictions than the FileReference class.
Upvotes: 1