1 Reply Latest reply on Aug 26, 2010 9:59 PM by seaneyefi

    NativeDragManager and canceling a dnd operation

    seaneyefi Level 1

      Hi all,


      I'm developing an HTML/JavaScript based AIR 2.0.3 desktop application where I want to make use of the File Promises APIs. Here's what my code looks like:


      var cb = new air.Clipboard(), promises = [];

      for(var i = 0, l = this._urls.length; i < l; i++) {

      var fp = new air.URLFilePromise();

      fp.request = new air.URLRequest(this._urls[i].url);

      fp.relativePath = this._urls[i].fileName;



      cb.setData(air.ClipboardFormats.FILE_PROMISE_LIST_FORMAT, promises);

      air.NativeDragManager.doDrag(window.htmlLoader, cb);


      So, I can pop a few urls into the clipboard and have them download to the local file system when the user drags an few files out of my AIR application.


      Here's what I'd like to be able to do though:


      While the user is dragging the files out of my AIR application, I'd like to be able to cancel the dnd operation to prevent them from dropping them based on certain criteria. Is there any way to do this? I tried invoking the air.NativeDragManager.dragInitiator.stopDrag method, but no luck there. I tried dispatching a NATIVE_DRAG_COMPLETE event to try to trick the NativeDragManager into thinking that the drag operation had stopped, but no luck there either.


      Anyone any ideas on this





      Also - is anyone aware of a way to customize the little sprite that appears beside the user's cursor when they start a native drag and drop operation? I'd like to be able to display a thumbnail of the file the user is dragging out of my AIR application beside their cursor instead of the default 'jpeg' avatar/sprite during a drag and drop.

        • 1. Re: NativeDragManager and canceling a dnd operation
          seaneyefi Level 1

          Tried the following code in an attempt to fake out an artificial drop:


          window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _START, dojo.hitch(this, function(evt) {

          // evt.dataTransfer here is undefined ... cannot use setDragImage() function to style the avatar which appears beside the user's mouse


          window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _ENTER, dojo.hitch(this, function(evt) {

          // thought that this would force the drop, but no dice

          // air.NativeDragManager.acceptDragDrop(window.htmlLoader);


          window.htmlLoader.addEventListener(window.runtime.flash.events.NativeDragEvent.NATIVE_DRAG _UPDATE, function(evt) {

          if(aCertainConditionIsMet()) {

          // dispatch a drop event which will be caught in the NATIVE_DRAG_ENTER callback above

          window.htmlLoader.dispatchEvent(new window.runtime.flash.events.NativeDragEvent(window.runtime.flash.events.NativeDragEvent.N ATIVE_DRAG_DROP));





          I get the feeling from the code above that I'm trying to force this functionality - is what I'm trying to achieve advisable/possible with AIR?