Skip to main content
May 16, 2011
Answered

Creating external files (.txt, .json, etc)

  • May 16, 2011
  • 2 replies
  • 4028 views

Hello everyone,

I'm currently trying to find out how to create external files from a SWF/exe/app file created in Flash. Essentially I'm building a program to create templates for levels in a game. The SWF will be run locally (e.g. not online) and will allow the user to add/remove objects to a level of their design. They then need to be able to save the level template (ideally I need to be able to save as a JSON* file, but I'm sure I could get away with just a simple txt file) somewhere on their computer. These templates will them be imported by the game itself (not written in Flash, hence why I need to save the data as a json or txt file), which will then re-create the levels from the data contained in the save file.

I had assumed this would be something that was really simple to do, but I cannot seem to find any tutorials or information on how to create external files. I can find plenty on reading from existing external files, but nothing about actually writing a new file entirely. I have read a few people complaining that non-local Flash SWFs cannot access the user's hard drive for security reasons, but cannot find any information on local SWFs.

If anyone could tell me even roughly what I'm looking for, it would be greatly appreciated. I'm a bit stuck just now haha

*I have downloaded the corelib files which allow me to work with JSON files

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

If user is involved (you are not talking about automatic saving), you can use FileReference.save() method.

Here is is documentation with example:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#save()

If use AIR - things can be more sophisticated.

2 replies

Andrei1-bKoviICorrect answer
Inspiring
May 16, 2011

If user is involved (you are not talking about automatic saving), you can use FileReference.save() method.

Here is is documentation with example:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html#save()

If use AIR - things can be more sophisticated.

May 16, 2011

Ahaha that looks perfect! Just what I needed - brilliant.

aneelbakshi
Inspiring
May 16, 2011

Flash is not able to write any type of text file on user system.

U have to use air or zinc to intract with file system.

Yes u can use shared objects also. Which stores value to user computer and browser stores cookies on user system

May 16, 2011

Ah that's what I was afraid of.So even local files cannot interact with the file system? I thought it would only be online ones. Curses that makes things difficult. Thank you for your help.

I think it's possible to do what I need using a SWF running on an external file and some PHP script, but seeing as I don't know any PHP this would be a complete pain. I'll look into using air instead.