Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Handling drag and drop with Mediator  (Read 11924 times)
mkaffel
Newbie
*
Posts: 4


View Profile Email
« on: August 12, 2009, 03:11:51 »

Hello,

I tried to handle Drag and Drop from a DataGrid to an Image for deleting an element but I have some troubles.

Without PureMVC, I handle the events DragEnter and DragDrop in this way :


            private function image_dragEnter(evt:DragEvent):void {
                var obj:IUIComponent = IUIComponent(evt.currentTarget);
                DragManager.acceptDragDrop(obj);
            }

            private function image_dragDrop(evt:DragEvent):void {
                var item:Object = dataGrid.selectedItem;
                var idx:int = arrColl.getItemIndex(item);
                arrColl.removeItemAt(idx);
            }


When i try to past event to Mediator, only one event is dispatched (randomly).

I don't understand what's happen!

I will be glad if someone can help me.

Thanks in advance
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: August 12, 2009, 07:59:15 »

When i try to past event to Mediator, only one event is dispatched (randomly).

Which event are you trying to pass to the mediator and how? What is your intended sequence of events?

-=Cliff>
Logged
mkaffel
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: August 13, 2009, 01:34:05 »

I try to past the events DragEnter in first and then DragDrop :

DragBar.mxml :


<mx:Script>
      <![CDATA[
                      public static const ARCHIVE_DRAG_DROP:String = 'archiveDragDrop';
         public static const ARCHIVE_DRAG_ENTER:String = 'archiveDragEnter';   
                       
                   private function sendDragEvent( action:String ):void
                  {
                     dispatchEvent(new DragEvent( action, true ));
                  }                           
      ]]>
</mx:Script>

<mx:LinkButton id="archiveButton" label="Archive"
            icon="{archiveIcon}"
            dragDrop="sendDragEvent(ARCHIVE_DRAG_DROP)"
                                dragEnter="sendDragEvent(ARCHIVE_DRAG_ENTER)"
                                toolTip="Drop an element here for archiving" />


DragBarMediator.mxml :



                public function UniverseDragBarMediator(viewComponent:Object=null)
      {
         super(NAME, viewComponent);
         // Add Listeners
         universeDragBar.addEventListener( UniverseDragBar.ARCHIVE_DRAG_DROP, onArchiveDragDrop );
         universeDragBar.addEventListener( UniverseDragBar.ARCHIVE_DRAG_ENTER, onArchiveDragEnter );
      }

      private function onArchiveDragEnter( event:DragEvent ):void
      {
          var obj:IUIComponent = IUIComponent(event.currentTarget);
                        DragManager.acceptDragDrop(obj);
                       
      }

      private function onArchiveDragDrop( event:DragEvent ):void
      {
         sendNotification( ProjectManagerFacade.ARCHIVE_ELEMENT );
      }


I follow the flow  with PureMVC Console and I saw that only the event dragEnter is dispatched.

With the same code in first post, the both are dispatched.

Have you an explanation ???

Thanks for your help Cliff



Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: August 15, 2009, 07:58:36 »

Yes, you are dropping the ball when you try to rebroadcast the dragEnter. You are creating a new DragEvent and sending it, but the newly dispatched event does not carry the key bit of information from the original event: the object being dragged.


So when the Mediator tries:

:
private function onArchiveDragEnter( event:DragEvent ):void
{
   var obj:IUIComponent = IUIComponent(event.currentTarget);
    DragManager.acceptDragDrop(obj);
                       
}

'obj' will be null, and therefore the accept will fail, causing the DragDrop event not to be sent.

-=Cliff>
Logged
Pages: [1]
Print