Drag and Drop

Devin Asay devin_asay at byu.edu
Thu May 9 11:03:01 EDT 2013


On May 9, 2013, at 6:15 AM, Ray Horsley wrote:

> I've never used this feature before and no matter how I set it up it seems kind of sporadic.  The goal is to drag an image file (jpg, jpeg, png, etc.) from the desktop onto a card, get the path to it and ultimately import it into the stack.  I've place an image control on the card which is the same dimensions as the stack itself and scripted the following:
> 
> on dragEnter
>   set the dragAction to "copy"      -- this is the sporadic part which only sometimes turns the cursor into a plus thus allowing dragDrop to catch the drop
>   pass dragEnter
> end dragEnter
> 
> on dragDrop
>   put the dragData into curFilePath
>   -- continue to import the file
> end dragDrop
> 
> This works 'some of the time' but I'm still often unable to drop what I'm dragging since the cursor doesn't always turn into the plus sign.  Each time this happens I try dragging the file again, immediately, and it suddenly works when I didn't change a thing.  What am I missing to get drag/drop working consistently?

Ray,

A while back I needed exactly this. I worked out a process that seems to work consistently. Here's what I did:

In the card script:

on dragStart
    set the allowableDragActions to "move,copy"
end dragStart


In the drop target object script (mine happened to be a group):

on dragEnter
    set the dragAction to "move"  # "copy" might work, too
    # these next 3 lines are just eye candy to tell the user that they hit a "hot spot"
    set the lineSize of grc "dropSpot" of me to 3
    set the backcolor of grc "dropSpot" of me to "gray"
    set the icon of btn "downArrowBtn" to "downarrow"
end dragEnter

on dragDrop
    put the dragData["files"] into fld "file path"

    # more eye candy
    set the backcolor of grc "dropSpot" of me to the startingBackColor of grc "dropSpot" of me
    set the icon of btn "downArrowBtn" to "downarrowlite"
end dragDrop


on dragLeave
    # yet more eye candy
    set the backcolor of grc "dropSpot" of me to the startingBackColor of grc "dropSpot" of me
    set the icon of btn "downArrowBtn" to "downarrowlite"
end dragLeave

As you can see the essential parts of the drag-drop operation are fairly minimal and straightforward.

HTH

Devin


Devin Asay
Office of Digital Humanities
Brigham Young University





More information about the use-livecode mailing list