As if Flash Lite development combined with FMS wasn't enough fun already I decided to start yet another side project, this time using AIR. The idea behind the project is to build (yet another) webcam snapshot tool - but with a twist.
I use Freeagent for my company accounts (which I can highly recommend btw - just note that multiple currency support is in the works and not yet supported - sorry to be harping on about this Olly ;-) and I would like to have a little tool that lets me capture, upload and attach receipts and other paper related snippets to specific transactions. Luckily, Freeagent have a cool API which I think will allow me to achieve what I want.
In short, you should eventually load up my AIR app, bring up a list of your company transactions and then by simply holding a receipt in front of the camera and pressing the space bar on your keyboard it will capture, save, upload and attach that image to the selected transaction. That surely must be easier than having to scan, save and upload the same receipt using traditional upload methods.
At worst I'll never finish it and waste a few days of my life but what the heck.
Ok, back on track to finally add some value to this post. While messing around with this application I couldn't quite figure out how in AIR I could pre-populate the File Save-As dialogue. I didn't want to the user to choose just any old name for the file (but they still could if they like to), and I also needed to add the default file extension to the image, in this case .png. So after some Tweeting (thanks @weyert) and Googling I came up with this - dead simple, but as usual only if you know how :-)
private function onSave(e:MouseEvent):void
//get a reference to the desktop and suggets a filename plus extension
var f:File = File.desktopDirectory.resolvePath('img.png');
//listen for the select event
//open the browse for save dialogue
// actually save the image
private function onBrowse(e:Event):void
// stuff from other parts of my app
var pngenc:PNGEncoder = new PNGEncoder();
var ba:ByteArray = pngenc.encode(bmd);
// grab the file that the user chose - hopefully as suggested by me
var file:File = File(e.target);
var fileStream:FileStream = new FileStream();
//close the file
//called when user presses save button in my app
There. Documented here for your pleasure.
Oh, and while you're here: why not subscribe to my RSS Feed? I mean how hard can it really be to reach 1000 readers :)