2 Replies Latest reply on Jun 5, 2009 12:26 PM by maestro91

    Drag&Drop acceptDragDrop not working

    maestro91

      Hello, i'm having a problem implementing D&D on a customized Image component while dragging over a Canvas.

      The problem is that when a runtime generated UserImage gets dragged over the drop target canvas, the dragproxy don't change in the "acceptDragDrop" shape ...

       

      Significant code:

       

      UserImage.as

      package com.lutek.components
      {
          import flash.events.MouseEvent;
          
          import mx.controls.Image;
          import mx.events.*;
          import mx.core.DragSource;
          import mx.managers.DragManager;
          public class UserImage extends Image
          {
              //public var name:String = new String;
              public var description:String = new String;
              
              public function UserImage()
              {
                  super();
                  addEventListener(flash.events.MouseEvent.MOUSE_MOVE, DragImage);
              }
              
              private function DragImage(event:MouseEvent):void {
                  
                  // Get the drag initiator component from the event object.
                  var dragInitiator:UserImage=this;
                  
                  // Create a DragSource object.
                  var ds:DragSource = new DragSource();
                  // Add the data to the object.
                  ds.addData(this, "UserImage");
                  // Call the DragManager doDrag() method to start the drag. 
                  DragManager.doDrag(dragInitiator, ds, event);
              }
          }
      }
      

       

      generatos.as

       

      ........................
      
      
              private function dragEnterHandler(event:DragEvent):void {
      
                  if (event.dragSource.hasFormat("UserImage")) {
      
                      var dropTarget:Canvas=Canvas(event.currentTarget);
                      trace("over " + dropTarget.id); 
                      DragManager.acceptDragDrop(dropTarget);
                  }
              }
                      
              private function dragDropHandler(event:DragEvent):void {
                  trace("DropOk");
              }
      
      .........................
      

      generator.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application 
           applicationComplete="_init();" 
           xmlns:my="*" 
           xmlns:custom="com.lutek.components.*"  
           xmlns:mx="http://www.adobe.com/2006/mxml" 
           layout="absolute" 
           width="875" 
           height="635">
      <mx:Script source="generator.as"/>
      .....................
      <mx:Canvas width="100%" height="100%" id="pnlContainer"
                                      dragEnter="dragEnterHandler(event);" 
                                      dragDrop="dragDropHandler(event);"
                          >
      .....................
      

       

      Any idea? I'm new to everything concerning Flex, and more on Flex's D&D ....

      Maybe the problem is in generator.as, because the trace works so it seems the problem is DragManager.acceptDragDrop(dropTarget) ...

      Thanks to everyone