topleft topright

Welcome, Guest. Please login or register.
May 25, 2013, 12:49:00 AM
Home Help Search Login Register
News: ATTENTION: Spambots must die! Humans must visit http://contact.futurescale.com to request forum access.

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


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

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: 2790



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

Quote
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 AM »

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 Huh

Thanks for your help Cliff



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



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

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:

Code:
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
Jump to:  



Login with username, password and session length

Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC
Copyright © 2006-2008 Futurescale, Inc.