Yeah , I know its very simple..,but a friend asked me to do it for him.. so as well putting it here too…
(I am too lazy to specially write examples for blog
)
Not much to explain in code.. very simple use of native methods of DragManager in AIR and Datagrid
here it is …
<?xml version=”1.0″ encoding=”utf-8″?><mx:WindowedApplication
creationComplete=”onCreationComplete()”
xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute”>
<mx:Script >
import flash.desktop.ClipboardFormats;
import flash.events.NativeDragEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import mx.managers.DragManager;
//called when app has initialized and is about to display
private function onCreationComplete():void
{
//register for the drag enter event
addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
//register for the drag drop event
addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);
}
//called when the user drags an item into the component area
private function onDragIn(e:NativeDragEvent):void
{
//check and see if files are being drug in
if(e.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT))
{
var files:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
DragManager.acceptDragDrop(this);
}
}
//called when the user drops an item over the component
private function onDragDrop(e:NativeDragEvent):void
{
//get the array of files being drug into the app
var arr:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
uploadGrid.dataProvider = arr;
}
</mx:Script>
<mx:VBox x=”70″ y=”10″ width=”355″>
<mx:DataGrid id=”uploadGrid” height=”130″ width=”100%” >
<mx:columns>
<mx:DataGridColumn width=”150″ dataField=”name”/>
<mx:DataGridColumn width=”150″ dataField=”size” />
</mx:columns>
</mx:DataGrid>
<mx:Text text=”Drag a Text File into the Application”
width=”233″ height=”148″ top=”11″ left=”10″/>
</mx:VBox>
</mx:WindowedApplication>
Filed under: RIA/ FLEX/ AS , AIR, Drag drop