startDrag issues
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 86
- Joined: Tue May 15, 2012 5:56 pm
startDrag issues
I have 2 groups setup and I have loaded images into the first group. I want to be able to drag images from group 1 to group 2 but the images in group 1 do not seem to do anyting in the dragStart command. I have been checking out the article http://lessons.runrev.com/s/lessons/m/4 ... t-a-primer but it does not seem to help me with my issue. Can someone out there point me in the right direction.
Re: startDrag issues
Just off the top of my head, "dragstart" is a message, not a command. It is sent when a drag action is initiated, and allows one to trap and handle stuff.
But I think you need to look up the "move" command, and the "dragMove" message.
Another tack is to use "mouseMove", which may better fit your needs. Check these out, experiment, and write back.
Craig Newman
But I think you need to look up the "move" command, and the "dragMove" message.
Another tack is to use "mouseMove", which may better fit your needs. Check these out, experiment, and write back.
Craig Newman
-
- Livecode Opensource Backer
- Posts: 328
- Joined: Mon Dec 05, 2011 5:34 pm
- Contact:
Re: startDrag issues
Hi CM79
I too fought with trying to understand the whole Drag process based on that lesson/article - then gave up!! It's a bit useless unless a basic background is given - which "pinning to the mat" didn't. I really hope someone can come out with a much clearer explanation of the built in drag stuff.
For my purposes I ended up rolling my own basic drag manager - which isn't actually all that hard. Basically have a object level script that checks for mousedown and sets a global flag to tell the program it's now in drag mode, the id of the dragged object and store the mouse loc offset from the object loc, then have another card level script to handle the mousemove - which applies the stored offset difference from the mouseloc to the object (this can also check for edge boundaries before application). There should also be a mouseup to quit the dragging process, reset the dragging flag, etc.
I'm not at my machine just now so this is pseudocode:-
--- in the object to be dragged
on mousedown
put the loc of me into tLoc
put the mouseloc into tMLoc
put item 1 of tLoc - item 1 of tMLoc into gDragXoff
put item 2 of tLoc - item 2 of tMLoc into gDragYoff
put the ID of me into gDragObjID
// possibly might need "grab me" here
put true into gDragFlag
end mousedown
on mousemove
pass mousemove
end mousemove
--- in the card/stack
on mousemove x,y
if gDragFlag then
// this next bit can be done in multiple stages to do checking, special effects, etc
// you should also ask any drop area items if the x,y is over them here (remember the result ready for the mouseup)
put (x+gDragXoff) & "," & (y+gDragYoff) into tNewLoc
set the loc of ID gDragObjID to tNewLoc
end if
end mousemove
on mouseup
// you should tell drop area items that they have been dropped on here
put false into gDragFlag
end mouseup
I cannot say for certain that the above will work for you, but it's an alternative (if it's even correct!)
BTW, it works fine on the iPad too - mouse down/move/up are all handled Ok.
Cheers,
Dave
I too fought with trying to understand the whole Drag process based on that lesson/article - then gave up!! It's a bit useless unless a basic background is given - which "pinning to the mat" didn't. I really hope someone can come out with a much clearer explanation of the built in drag stuff.
For my purposes I ended up rolling my own basic drag manager - which isn't actually all that hard. Basically have a object level script that checks for mousedown and sets a global flag to tell the program it's now in drag mode, the id of the dragged object and store the mouse loc offset from the object loc, then have another card level script to handle the mousemove - which applies the stored offset difference from the mouseloc to the object (this can also check for edge boundaries before application). There should also be a mouseup to quit the dragging process, reset the dragging flag, etc.
I'm not at my machine just now so this is pseudocode:-
--- in the object to be dragged
on mousedown
put the loc of me into tLoc
put the mouseloc into tMLoc
put item 1 of tLoc - item 1 of tMLoc into gDragXoff
put item 2 of tLoc - item 2 of tMLoc into gDragYoff
put the ID of me into gDragObjID
// possibly might need "grab me" here
put true into gDragFlag
end mousedown
on mousemove
pass mousemove
end mousemove
--- in the card/stack
on mousemove x,y
if gDragFlag then
// this next bit can be done in multiple stages to do checking, special effects, etc
// you should also ask any drop area items if the x,y is over them here (remember the result ready for the mouseup)
put (x+gDragXoff) & "," & (y+gDragYoff) into tNewLoc
set the loc of ID gDragObjID to tNewLoc
end if
end mousemove
on mouseup
// you should tell drop area items that they have been dropped on here
put false into gDragFlag
end mouseup
I cannot say for certain that the above will work for you, but it's an alternative (if it's even correct!)
BTW, it works fine on the iPad too - mouse down/move/up are all handled Ok.
Cheers,
Dave
Coding in the Sun - So much Fun.
Visit http://electronic-apps.info for released App information.
Visit http://electronic-apps.info for released App information.
Re: startDrag issues
Hi friends,
Please post (parts of) you script so we can check what might not work as intended.
We need to know WHAT you scripted and WHERE you put the script(s).
Best
Klaus
come on, something like "do not seem" etc. is not really helpful for us to find any errors in your (yet unkown) script(s)!CenturyMan1979 wrote:I have 2 groups setup and I have loaded images into the first group. I want to be able to drag images from group 1 to group 2 but the images in group 1 do not seem to do anyting in the dragStart command. I have been checking out the article http://lessons.runrev.com/s/lessons/m/4 ... t-a-primer but it does not seem to help me with my issue. Can someone out there point me in the right direction.
Please post (parts of) you script so we can check what might not work as intended.

We need to know WHAT you scripted and WHERE you put the script(s).
Best
Klaus
-
- Posts: 86
- Joined: Tue May 15, 2012 5:56 pm
Re: startDrag issues
Well guess I just needed to step away from the project last night and come look at it with some refreshed eyes. Turns out I had the dragStart inside of the wrong object so it was never triggering. So I have the dragStart working and I can even drag some data to another image object in another group. Like so
Turns out this will not work
(Group 1 image object)
(Group 2 image object)
Only problem with this method is that you can't trigger dragEnter or dragDrop on a group itself unless you are over a control in the group. The reason it is a problem is that I want to have an empty group 2 that will handle the dragEnter and dragDrop. Guess I will handle the drag n drop at the card level with my own custom script.
Turns out this will not work
(Group 1 image object)
Code: Select all
on dragStart
set the dragImage to the id of me
set the dragData["text"] to the folder & "/" & the filename of me -- Is there a better way to get the absolute file path for an image?
end dragStart
Code: Select all
on dragEnter
set the dragAction to copy
end dragEnter
on dragDrop
set the fileName of me to the dragData["text"]
end dragDrop
Re: startDrag issues
Hi CenturyMan1979,
yep, scripts look ok!
Hint: use parens whenever you concatenate a string.
Works here and most of the time, but will fail when you least exspect it, I know what I'm talking about
:
...
set the dragData["text"] to (the folder & "/" & the filename of me)
...
I always put an opaque graphic into (empty) groups, so they will accept drag/drop/mouseXYZ etc.!
Groups are really just containers and do NOT react on any action themselves, therefore this workaround.
Best
Klaus
yep, scripts look ok!
Hint: use parens whenever you concatenate a string.
Works here and most of the time, but will fail when you least exspect it, I know what I'm talking about

...
set the dragData["text"] to (the folder & "/" & the filename of me)
...
I always put an opaque graphic into (empty) groups, so they will accept drag/drop/mouseXYZ etc.!
Groups are really just containers and do NOT react on any action themselves, therefore this workaround.
Best
Klaus