2 Replies Latest reply on Oct 28, 2009 1:32 AM by vertmonkee

    Draggin files out of FileSystemTree

    vertmonkee

      I have been working on my first drag and drop upload application. Everything goes fie when I drag a file from the OS (e.g. from the Desktop into the AIR App). I have added a FileSystemTree and set dragEnabled to true but it does not let me drag a file from it onto the upload area.

       

      Here is my code

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="onCreationComplete()">

       

          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import mx.managers.DragManager;
                 
                  //Called when app has initialized and is about to display
                  private function onCreationComplete():void {
                      //Register for the drag enter event
                      dragArea.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
                      //Register for the drag drop event
                      dragArea.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);
                  }
                 
                  //Called when the user drags an item into the component area
                  private function onDragIn(e:NativeDragEvent):void {
                      trace("onDragIn function called");
                      //Check and see if files are being dragged in
                      if(e.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)) {
                          //Get the array of files
                          var files:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                          //Make sure only one file is dragged in (i.e. this app doesn't support dragging in multiple files)
                          if(files.length == 1) {
                              //Accept the drag action
                              //DragManager.acceptDragDrop(this);
                              DragManager.acceptDragDrop(dragArea);
                          }
                      }
                  }
                 
                  //Called when the user drops an item over the component
                  private function onDragDrop(e:NativeDragEvent):void {
                      trace("onDragDrop function called");
                      //Get the array of files being dragged into the app
                      var arr:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
                     
                      //Grab the files file
                      var f:File = File(arr[0]);
                     
                      //Call the upload function
                      uploadFile(f);
                  }
                 
                  private function uploadFile(file:File):void {
                      Alert.show("File uploaded");
                      var request:URLRequest = new URLRequest('http://localhost/airapps/DragAndDropUpload/upload.php');
                      file.upload(request);
                  }
                          
              ]]>
          </mx:Script>
         
          <mx:Text text="Drag a Text File into the Application" />
          <mx:FileSystemTree id="draggableFileTree" dragEnabled="true" width="90%" height="50%"/>
          <mx:Label text="Drag a file here" id="dragArea"/>

       

         
      </mx:WindowedApplication>

       

      The php script simply takes the file and moves it to a folder on the server.

       

      Can anyone tell me why I am having no luck in dragging the file out of the system tree?

       

      Thanks for any help.