1 Reply Latest reply on Oct 10, 2008 10:02 AM by abeall

    Drag and drop questions

    abeall Level 3
      1) When listen for nativeDragEnter on the stage, it only accepts drag when the mouse is over a DisplayObject. Is there a way to make the whole stage/window accept the drag?

      2) I'm dragging in files for the use of uploading. I only want to accept pdf, doc, and ppt files. How do I filter the allow drag to only accept those file types? After the drop I can determine what was dropped, but I want to make the icon show a "denied" state during the drag operation if the file type is not right.
        • 1. Drag and drop questions
          abeall Level 3
          I figured out how to do the file filtering (below.)

          However, I'm still stuck on 1). I can't figure out how to just make the whole app accept the drop. If I set it to stage, it only seems to detect nativeDragEnter when the mouse is over some graphics, but not when it's over empty canvas, and not when it's over another InteractiveObject that has mouse event listeners. What's worse, if I put an invisible object over the entire stage and add nativeDragEnter listener to it, it steals focus from everything below it.

          var allowedTypes:Array = ['.pdf','.doc','.ppt'];
          stage.addEventListener('nativeDragEnter',dragEnter);
          function dragEnter(evt:NativeDragEvent){
          if(evt.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)){
          var files:Array = evt.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
          if(files.length == 1){
          if(allowedTypes.indexOf(files[0].type.toLowerCase()) != -1){
          NativeDragManager.acceptDragDrop(stage);
          }
          }
          }
          }