FlashComGuru Home InfluxisCDNImediaseeUvault
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (11)
Applications (40)
Books & Training (11)
Collaboration (18)
Components (10)
Events (80)
Flash Player (35)
Flex (39)
FMS (110)
General (123)
Hosting (6)
Jobs (17)
Off topic (36)
OSMF (3)
Press Releases (23)
Site Check (11)
Tools (53)
Videos & Players (74)

Follow me on Twitter

 
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 :-)

//called when user presses save button in my app
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
f.addEventListener(Event.SELECT, onBrowse);
//open the browse for save dialogue
f.browseForSave("Save Image");
}

// 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();

try{
fileStream.open(file,FileMode.WRITE);
fileStream.writeBytes(ba);               
//close the file
fileStream.close();            
}
catch(e:Error)
{            
trace(e.message);            
}
}

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 :)

Comments
[Add Comment]
Thanks very much for the tip, just when I needed it :)

maw
# Posted By maw | 9/21/09 4:54 PM
good stuff thanks. There does not seem to be a way to suggest the file name without also specifying the folder location...
# Posted By felix | 11/21/09 9:13 PM