Ever wanted to dynamically write local files from a Flash game/app at runtime (without server-side scripts, or annoying File Dialog prompts)? This handy AIR app can serve as a 3rd-arm for your Flash projects that needs to dynamically update JSON, TXT, or even ByteArray files. Also useful for launching NativeProcess (batch, commands, etc.)
ActionScript Shell
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bat
bin-client
bin
images
libs
src
.gitignore
AIRFileSave Test.as3proj
AIRFileSave Test.lxml
AIRFileSave.as3proj
AIRFileSave.lxml
AIR_readme.txt
MyPackager.bat
PackageApp.bat
README.md
Run.bat
application.xml

README.md

AIRFileSave

Latest Updates:

You can now Append data to a file (instead of having to remember the whole file each time). This becomes useful for writing continuous logs, especially automated projects.

See what else has changed: https://github.com/bigp/AIRFileSave#updates


Ever wanted to dynamically write local files from a Flash game/app at runtime (without server-side scripts)? This handy AIR app can serve as a 3rd-arm for your Flash projects that needs to dynamically update JSON, TXT, or even ByteArray files. Also useful for launching NativeProcess (batch, commands, etc.)


It's true, there already exists a way of saving files from a Flash app by prompting a FileReference dialog, letting the user pick a path / filename and saving the bytearray to the user's system.

But what if you're working on a personal project? What if you're adjusting certain values in an XML or JSON file to tweak your game's flow? What if you're calibrating the scroll speed of your UI menus? Are you going to constantly go back and forth between editing and compiling your project until you get it right?

A Different Approach

Since you probably know the path to the configuration/levels files of your game and/or app, why not integrate some kind of auto-save in your project?

The way this works - AIRFileSave is an AIR app that uses a LocalConnection approach to "listen" to the client (your game/app) to initiate any file writing / reading / directory-listing commands.

How it works

You ask: "If this is using LocalConnections, do I need to setup the client LocalConnection to communicate with the AIR app?" - No worries! You don't have to setup a bunch of cumbersome LocalConnection details yourself in your project! This is handled for you in the client SWC, which you can create from the AIR app directly:

How it works


Usage of Client SWC

//Instantiating a new Client automatically connects to the AIR app.
var theClient:AIRFileSaveClient = new AIRFileSaveClient();

//Save a plain text file:
theClient.saveText("myFileName.txt", "Hello World.");

//Save a byte-array file:
theClient.saveBytes("myDataFile.bin", theByteArray);

//List a Directory:
theClient.listDirectory("C:/Temp/", function( pFileNames:Array ):void {
    trace(pFileNames);
}

//Create / Remove:
theClient.createDirectory("theDirName", onDirCreated);
theClient.deleteDirectory("theDirName", onDirDeleted);
theClient.deleteFile("theFile.txt", onFileDeleted);

//Last but not least, here's a way to call a command (Batch) file: (not fully implemented yet)
theClient.startCommand( "theCommand.bat", ["Hello", "World"], onCommandCompleted);

Demo

You can find a pre-release *.EXE installer on this GitHub page: https://github.com/bigp/AIRFileSave/releases

Also, once you have the AIR app running, you can try this online demo to see if it writes a plain text file under: C:\temp.txt

Try it: http://pierrechamberlain.ca/others/airfilesaveclient/index.html

Updates

(2014-08-14)

  • Added "appendText()" and "appendBytes()" methods to the Client and Server.
  • Refactored so that appendText/appendBytes/saveText/saveBytes reuse the same core method but only differ in which FileMode (APPEND vs. WRITE) type they use.