File promises with Adobe AIR 2.0
File promises is one of the new AIR 2.0 features already available in beta on Adobe Labs. “A file promise is a drag-and-drop clipboard format that allows a user to drag a file that does not yet exist out of an AIR application. AIR uses the methods and properties defined by the IFilePromise interface to access the data to be written when the file promise is dropped.” To check out how it works, I built a sample application that allows you drag an AIR icon out of the app and drop it somewhere in your system (e.g. on your desktop). Dropping it will initiate a download of the current stable AIR runtime installer (at this point in time it is AIR 1.5.3). The downloaded file containing the runtime will be appropriate for your operating system. This logic is implemented in the fileUrl function and it uses the Capablities.os property with a simple regexp search for “win”, “lin”, or “mac” patterns.
Here is how the application looks:

Below is the source code:
<?xml version="1.0" encoding="utf-8"?> <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:halo="library://ns.adobe.com/flex/halo" currentState="START_STATE" height="200" width="300" viewSourceURL="srcview/index.html"> <s:layout> <s:VerticalLayout horizontalAlign="center" gap="15"/> </s:layout> <fx:Script> <![CDATA[ import flash.events.Event; import flash.events.MouseEvent; import flash.system.Capabilities; protected var filePromise:URLFilePromise; protected function imgAirIcon_mouseDownHandler(event:MouseEvent):void { // Instantiating new file promise filePromise = new URLFilePromise(); // Registering OPEN event listener, to switch to // DOWNLOAD_STATE when downloading starts filePromise.addEventListener(Event.OPEN, onOpen); // Setting URLRequest pointing to remote file filePromise.request = new URLRequest(fileUrl); // Setting relativePath with fileName to be saved locally filePromise.relativePath = fileName; // Array of promises with single promise in this case var promises:Array = new Array(); promises.push(filePromise); // Instantiating clipboard object pointing to the promise var clipboard:Clipboard = new Clipboard(); clipboard.setData(ClipboardFormats.FILE_PROMISE_LIST_FORMAT, promises); // Dragging with NativeDragManager NativeDragManager.doDrag(imgAirIcon, clipboard); } protected function onOpen(event:Event):void { currentState = "DOWNLOAD_STATE"; prgBar.source = filePromise; } protected function get fileUrl():String { // Returns remote file URL based on current operating system if (Capabilities.os.search(/mac/i) > -1) return "http://airdownload.adobe.com/air/mac/download/latest/AdobeAIR.dmg"; else if (Capabilities.os.search(/win/i) > -1) return "http://airdownload.adobe.com/air/win/download/latest/AdobeAIRInstaller.exe"; else return "http://airdownload.adobe.com/air/lin/download/latest/AdobeAIRInstaller.bin"; } protected function get fileName():String { var fileUrl:String = fileUrl; return fileUrl.slice(fileUrl.lastIndexOf("/") + 1); } ]]> </fx:Script> <s:states> <s:State name="START_STATE"/> <s:State name="DOWNLOAD_STATE"/> </s:states> <halo:Image id="imgAirIcon" source="assets/air_icon_special.gif" mouseDown="imgAirIcon_mouseDownHandler(event)" toolTip="{fileUrl}" /> <s:Label text="(Drag it out to start download)" /> <halo:ProgressBar id="prgBar" bottom="10" horizontalCenter="0" visible="false" visible.DOWNLOAD_STATE="true" label="Downloading {int(prgBar.percentComplete)}%"/> </s:WindowedApplication>


Can you give any info on how to extact data from downloaded .ZIP files using AIR (for example extract zip into folder)
Ole jak
20 May 10 at 7:44 pm
I follow your website for quite a lengthy time and should tell that your content articles always prove to be of a high value and high quality for readers.
buy chun li costume
29 Sep 10 at 3:37 pm
This is a contribution excenelte friend does not know when it helped me to
Antoine Buzick
18 Oct 10 at 3:51 pm
Excellent info here, This is what i’m in search of. thanks, i’ve bookmark your web page.
Adeline Gironda
10 Dec 10 at 6:59 pm
I am trying to adapt your code to accept dragging an e-mail (and preferably with attachments) from a list of e-mails in the Thunderbird client into an AIR application.
Do you think that URLFilePromise is the way of doing it?
Can you give me a hint?
Thank you very much indeed.
Carlos
Carlos
10 Mar 11 at 2:57 am
Fantastic goods from you, man. I have be mindful your stuff previous to and you’re simply extremely excellent. I actually like what you have bought right here, really like what you’re stating and the best way during which you say it. You are making it entertaining and you still care for to keep it wise. I can’t wait to read far more from you. That is actually a tremendous website.
url shortener
29 Oct 11 at 3:25 am