I found the code at the end of this post while trying to learn about
drag and drop to an Air app.
It looks like it should do what I want, but generates two errors that I
have been unable to solve (I am still very much a newbie).
the errors are:
[SWF] DragDrop.swf - 1,284,532 bytes after decompressionError #2044:
Unhandled IOErrorEvent:. (2044 Unhandled %1:.) text=Error #2038: File
I/O Error. (2038 File I/O Error.) at
flash.desktop::Clipboard/getFileList() at <anonymous>() at
flash.desktop::Clipboard/convertNativeFormat() at
flash.desktop::Clipboard/getData() at DragDrop/onDrop()[D:\tex\My
Documents\Flex_Builder_3_Projects\DnD\OriginalDragAndDrop\src\DragDrop.m\
xml:41] The error seems to be pointing to the private onDrop function.
Can anyone offer any suggestions?
many thanks in advance, Tex
source code:
<?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication
xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="400"
height="300" creationComplete="onStartup(event);" >
<mx:Script><![CDATA[
import flash.desktop.*;import flash.filesystem.*;import
mx.utils.ArrayUtil;//newimport mx.collections.ArrayCollection; //new
private var _files:Array = [];
[Bindable] //newprivate var arrayCollection:ArrayCollection;//new
private function onStartup(event:Event): void { arrayCollection = new
ArrayCollection(); //new
addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDrop);}
private function onDragIn(event:NativeDragEvent):void {
if(event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)) { var
files:Array = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT)
as Array; if( files.length > 0 )
NativeDragManager.acceptDragDrop(this); }}
//error points to this functionprivate function
onDrop(event:NativeDragEvent) : void { for each ( var f:File in
event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array )
arrayCollection.addItem({name:f.name, size:f.size, object:f});//new
_files.push(f); uploadNextFile();}
private function uploadNextFile(event:Event=null) : void { if (
_files.length > 0 ) { var f1:File = _files.pop() as File;
f1.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadNextFile);
f1.upload( new URLRequest( 'http://localhost/Upload.php' ), 'Filedata'
); } dgFileList.dataProvider = _files;}
]]></mx:Script>
<mx:DataGrid id="dgFileList" width="100%" height="100%">
<mx:columns> <mx:DataGridColumn headerText="File Name" dataField="name"
width="100"/> <mx:DataGridColumn headerText="Size" dataField="size"
width="30"/> <mx:DataGridColumn headerText="Progress"
dataField="object" width="150"> <mx:itemRenderer> <mx:Component>
<mx:HBox verticalAlign="middle"> <mx:ProgressBar id="ProgBar"
label="" height="6" source="{data.object}"/> </mx:HBox>
</mx:Component> </mx:itemRenderer> </mx:DataGridColumn>
</mx:columns> </mx:DataGrid>
</mx:WindowedApplication>