Pages

Monday 6 July 2009

Save functionality on CS4!

Finally what we've all been waiting for and it's really simple to implement.

I recently had to write some software for Braindash, a company I've been working for on and off for the last few years, who deal in puzzle games. The software was a brain training IQ puzzle generator thing, which had to take a puzzle and batch export several images for each question (a question and 4 answers) as well as a csv data file with information about the questions.

I actually didn't have a clue that writing data with flash without any serverside scripting was possible, so I'd given up on the idea after doing some reasearch into it a year or so ago. But now thats all changed which is absolutely fantastic.

File saving is done using the FileReference class, and the save method.

Implementation is as easy as:

var fileToSave:FileReference = new FileReference();
fileToSave.save(data,"name"+".extension");

where data can be:

- A String
- XML
- ByteArray data

If data is none of these, toString(); is called on whatever variables are in the data.

In the case of my work I used the AS3corelib PNGencoder to handle creating the byteArray from bitmapData in flash.

Enjoy this class, try making software which creates random art every time you open it and saves it to your desktop, pretty cool methinks!

Cheers

Sam

2 comments:

  1. Really useful, thanks!

    ReplyDelete
  2. For an example of what I used this for go to http://apps.facebook.com/kingofquizzes all of the images are batch produced using the PNG encoder and AS3 FileReference class.

    ReplyDelete