3 Replies Latest reply on Nov 16, 2009 11:07 AM by Windwalkerby

    FileSystemList drag and drop problem

    Windwalkerby

      Sorry, if this question was answered before, but I haven't found any solution

      So, I have a problem with dragging and droping data(files) between two FileSystemLists

       

      TypeError: Error #1034: Type Coercion failed: cannot convert Object@9a436c9 to flash.filesystem.File.
          at mx.collections::ListCollectionView/addItemsToView()[C:\autobuild\3.4.0\frameworks\project s\framework\src\mx\collections\ListCollectionView.as:912]
          at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.4.0\frameworks\proj ects\framework\src\mx\collections\ListCollectionView.as:1080]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.collections::ArrayList/internalDispatchEvent()[C:\autobuild\3.4.0\frameworks\projects\ framework\src\mx\collections\ArrayList.as:528]
          at mx.collections::ArrayList/addItemAt()[C:\autobuild\3.4.0\frameworks\projects\framework\sr c\mx\collections\ArrayList.as:309]
          at mx.collections::ListCollectionView/addItemAt()[C:\autobuild\3.4.0\frameworks\projects\fra mework\src\mx\collections\ListCollectionView.as:501]
          at ListCollectionViewCursor/insert()[C:\autobuild\3.4.0\frameworks\projects\framework\src\mx \collections\ListCollectionView.as:1892]
          at mx.controls.listClasses::ListBase/dragDropHandler()[C:\autobuild\3.4.0\frameworks\project s\framework\src\mx\controls\listClasses\ListBase.as:9313]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.4.0\frameworks\projects\framework\src \mx\core\UIComponent.as:9408]
          at mx.managers::NativeDragManagerImpl/_dispatchDragEvent()[C:\autobuild\3.4.0\frameworks\pro jects\airframework\src\mx\managers\NativeDragManagerImpl.as:625]
          at mx.managers::NativeDragManagerImpl/nativeDragEventHandler()[C:\autobuild\3.4.0\frameworks \projects\airframework\src\mx\managers\NativeDragManagerImpl.as:598]

       

       

      And  a piece of code related to lists:

       

      <mx:FileSystemList id="fileListFrom"
                             left="20" top="50"
                             width="{width/2-100}" height="{height/2-30}"
                             dragEnabled="true"  allowMultipleSelection="true" allowDragSelection="true"
                             extensions="{allowedFiles}" nativeDragEnter="onDragEnter(event)"
                             />
         
        <mx:FileSystemList id="fileListTo" directory="{File.applicationStorageDirectory.resolvePath('Files//')}"
                             right="20" top="50"
                             width="{width/2-100}" height="{height/2-30}"
                             dropEnabled="true" allowMultipleSelection="true"
                             extensions="{allowedFiles}"
                             dragDrop="dragDropHandler(event)"   />

       

          <mx:Script>
              <![CDATA[

                import mx.events.DragEvent;

                  import flash.desktop.NativeDragManager;
                  import flash.desktop.NativeDragActions;

       

                [Bindable]
                  private var allowedFiles:Array =['.txt', '.pdf'];

       

                  private function onDragEnter(event:NativeDragEvent):void {
                      NativeDragManager.acceptDragDrop(fileListTo);
                  }

       

                protected function dragDropHandler(event:DragEvent):void{
                      copyFiles();
                  }
                  private function copyFiles():void{
                     
                      var selectedFiles:Array = fileListFrom.selectedPaths;
                      for(var i:Number = 0; i<selectedFiles.length; i++){
                          var file:File = new File(selectedFiles[i]);
                          if(!file.isDirectory){
                              file.addEventListener(Event.COMPLETE,refreshHandler);
                              var destination:File = fileListTo.directory.resolvePath(file.name);
                              file.copyToAsync(destination,true);
                          }
                      }
                     
                  }


              ]]>
          </mx:Script>

       

       

       

      Sorry, I'm newbie in Flex and Air, but can anybody help me?