4 Replies Latest reply on Feb 8, 2010 3:56 PM by paus akid

    updating screen in NATIVE_DRAG_DROP handler?

    paus akid

      I'm trying to update the screen of my AIR application in the NATIVE_DRAG_DROP handler to display progress of processing the dropped files. So far I have not been sucessful, hopefully someone can point out my error:



      private var progress:Progress = new ProgressBar(); hitBox.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,onDragIn);                     hitBox.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,onDrop); 


      public function onDragIn(event:NativeDragEvent):void{

           NativeDragManager.dropAction = NativeDragActions.MOVE;         if(event.clipboard.hasFormat(ClipboardFormats.FILE_LIST_FORMAT)){          NativeDragManager.acceptDragDrop(hitBox);    




      public function onDrop(event:NativeDragEvent):void{     

      dropFiles = event.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;     

      dropFiles = cleanFileArray(dropFiles);     



      private function populatePlaylist(e:Event=null):void{     



      var i:int = 0;      

      for each (var file:File in dropFiles){


                 progress.update(i / (dropFiles.length+1));






      progress is never visible and never updates, but a trace statement inside of progress shows that it's getting called.


      I've also tried firing off an event inside of onDrop() when we are ready to exectue populatePlaylist() so that it can be asynchronous from the onDrop handler (hence the event handling in populatePlaylist) but that didn't help anything.


      If anyone is curious this code is in my open source CCCatcher application, you can dig into the main.CCCatcher class to see this stuff.


      This is under OSX 10.5.8.


      Any thoughts appreciated!

        • 1. Re: updating screen in NATIVE_DRAG_DROP handler?
          Joe ... Ward Level 4

          Your for loop in populatePlaylist() is going to execute almost immediately (unless there are thousands of files in the list). There's really no processing going on, so what do you expect will take enough time to warrent a progress display?

          • 2. Re: updating screen in NATIVE_DRAG_DROP handler?
            paus akid Level 1

            Joe, thanks for the prompt response!


            Realisticly dropping a few hundred files takes a few seconds to process. Not a large window of time for the application to reamin unresponsive, but long enough to display a progress indicator for a user wondering if anything is happening. Dropping a thousand files (a few months worth of music I've collected) causes a long enough pause that OSX starts spinning it's beach ball.


            This is just a point of polish so I understand if it's not possible to update the screen while the AIR runtime is handling a NATIVE_DRAG_DROP event. However, I thought I'd read how to do this somewhere and the link is now evading me.

            • 3. Re: updating screen in NATIVE_DRAG_DROP handler?
              Joe ... Ward Level 4

              Well, there's the file drop itself, where the OS hands off the files to AIR and there's your for-loop in which you iterate through an array of the file names that have already been handed to you. If the pause occurs in the for-loop, then the solution is to only process a reasonable number of files at a time. If the pause is while the OS is talking to AIR, then I don't think there's anything direct that you can do about it. (An indirect might be to show the progress bar on mouse-up over the drop target -- when a drag is in-progress -- and turn it off at the end of the drop handler -- I haven't tried this, though).


              If the pause is actually in the for-loop, then you can process only a small group of files at a time and use a listener for an asynchronous event (such as enter-frame) to trigger processing of the next batch until you are done. This will allow the UI time to update. See http://www.senocular.com/flash/tutorials/asyncoperations/ for an example.

              • 4. Re: updating screen in NATIVE_DRAG_DROP handler?
                paus akid Level 1

                Joe, that asyncoperations article from senocular.com was exactly what I was looking for. I've implemented + committed something similar to what Trevor suggests and my application no longer beach balls osx.


                Thanks very much!