RG1967
RG1967

Reputation: 378

flex- Drag and drop

I am trying to drag and drop an object across the SkinnableContainer- am coming across a very strange issue

The drop occurs only at a few places- elsewhere it just shows the "X" sign and on dropping there, reverts to original position. I have used very standard commands... from function 2 to function 3, the call occurs very rarely as seen in trace statements- any guidance on why this happens?

I added the following code to SkinnableContainer: dragEnter="dragEnterHandler(event);" dragDrop="dragDropHandler(event);

(1):

private function mouseMoveHandler(event:MouseEvent):void    
{
  var dragInitiator:Image = Image(event.currentTarget);   
  var ds:DragSource = new DragSource();    
  ds.addData(dragInitiator,"img"); //made change here    
  DragManager.doDrag(dragInitiator, ds, event);
}

(2):

private function dragEnterHandler(event:DragEvent):void {

if (event.dragSource.hasFormat("img"))
{
   trace("came here"); //comes here for each mouse move     
   DragManager.acceptDragDrop(SkinnableContainer(event.currentTarget));
}

(3):

private function dragDropHandler(event:DragEvent):void {    
trace("in drag drop handler"); //doesn't come here for most places

Upvotes: 2

Views: 1492

Answers (1)

merv
merv

Reputation: 76700

According to the Using Flex 4 reference:

To use a container as a drop target, you must use the backgroundColor property of the container to set a color. Otherwise, the background color of the container is transparent, and the Drag and Drop Manager is unable to detect that the mouse pointer is on a possible drop target.

In the subsequent example, they use an mx container (Canvas), but I checked the AS3 reference, and spark.components.SkinnableContainer does have a style backgroundColor.

I haven't tried this myself, so please confirm whether it is the issue. From your description that only certain parts of the container are registering the dragEnter event, this seems like a consideration that would lead to such effects.

Upvotes: 2

Related Questions