1 Reply Latest reply on Oct 3, 2011 10:17 PM by Joe ... Ward

    issues with drag and drop/file browse functionality in air file uploader

    madhooper Level 1

      Use Case: User can drag and drop a file into a datagrid or browse to the file and add it to the datagrid before uploading files to the server.

       

      The file browse functionality works fine. I put all the selected files in to an array and display them in a datagrid.

       

      Issue: I'm need to allow the user to also drag and drop a file into the datagrid from the file desktop and add that file to the upload que/datagrid.

       

       

       

      // Called to add file(s) for upload

                                    private function addFiles():void {

                                              _refAddFiles = new FileReferenceList();

                                              _refAddFiles.addEventListener(Event.SELECT, onSelectFile);

                                              _refAddFiles.browse();

                                    }

       

      // Called when a file is selected via file browser

                                    private function onSelectFile(event:Event):void {

                                              var arrFoundList:Array = new Array();

        // Get list of files from fileList, make list of files already on upload list

                                              for (var i:Number = 0; i < _arrUploadFiles.length; i++) {

                                                        for (var j:Number = 0; j < _refAddFiles.fileList.length; j++) {

                                                                  if (_arrUploadFiles[i].name == _refAddFiles.fileList[j].name) {

                                                                            arrFoundList.push(_refAddFiles.fileList[j].name);

                                                                            _refAddFiles.fileList.splice(j, 1);

                                                                            j--;

                                                                  }

                                                        }

                                              }

                                              if (_refAddFiles.fileList.length >= 1) {

                                                        for (var k:Number = 0; k < _refAddFiles.fileList.length; k++) {

                                                                  _arrUploadFiles.push({

                                                                            name:_refAddFiles.fileList[k].name,

                                                                            size:formatFileSize(_refAddFiles.fileList[k].size),

                                                                            file:_refAddFiles.fileList[k]});

                                                        }

                                                        listFiles.dataProvider = _arrUploadFiles;

                                                        tile.dataProvider = _arrUploadFiles;

                                                        listFiles.selectedIndex = _arrUploadFiles.length - 1;

                                              }

                                              if (arrFoundList.length >= 1) {

                                                        Alert.show("The file(s): \n\n• " + arrFoundList.join("\n• ") + "\n\n...are already on the upload list. Please change the filename(s) or pick a different file.", "File(s) already on list");

                                              }

                                              updateProgBar();

                                              scrollFiles();

                                              uploadCheck();

                                    }

       

      Bad/Broken Code--------------------------- Called when user attempts to drop file into the datagrid.

      private function onDragEnter( event:NativeDragEvent ) :void

                                    {

                                              DragManager.acceptDragDrop(this);

                                    }

       

                                    private function onDragDrop( event:NativeDragEvent ) :void

                                    {

                                              NativeDragManager.dropAction = NativeDragActions.COPY;

                                              var draggedfiles:Array = event.clipboard.hasFormat(flash.desktop.ClipboardFormats.FILE_LIST_FORMAT) as Array;

                                              NativeDragManager.acceptDragDrop(InteractiveObject(event.currentTarget));

                                              for each (var f:File in draggedfiles)

                                              {

        //addFile( FileReference( f ) );

                                                        _arrUploadFiles.push( f );

                                              }

                                    }

       

       

      What am I missing? Any assistance would be greatly appreciated.