Yes, it was not possible with Hypercardrichmond62 wrote: ↑Thu Feb 29, 2024 11:29 amYou are quite right: unfortunately I gave up declaring variables donkey's years ago, so had quite forgotten that.
But now, it's the same as in Javascript.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Yes, it was not possible with Hypercardrichmond62 wrote: ↑Thu Feb 29, 2024 11:29 amYou are quite right: unfortunately I gave up declaring variables donkey's years ago, so had quite forgotten that.
Because you want to track movement from where the user clicked, not the loc of the button, you have to also track the clickLoc. You also don't want the mouse being dragged outside of the button without dragging the button.
Code: Select all
local sLoc, sClickLoc
on mouseDown
put the loc of me into sLoc
put the clickLoc into sClickLoc
put sClickLoc & return
end mouseDown
on mouseMove x, y
if the mouse is down then put x & comma & y & return after msg
if abs(item 1 of sClickLoc - x) > 10 or abs(item 2 of sClickLoc - y) > 10 then
if sLoc is not empty then grab me
end if
end mouseMove
on mouseLeave
if the mouse is down and sLoc is not empty then grab me
end mouseLeave
on mouseUp
if the loc of me = sLoc then
answer "mouseUp stuff"
end if
put empty into sLoc
put empty into sClickLoc
end mouseUp
Code: Select all
local sLoc, sClickLoc
on mouseDown
put the loc of me into sLoc
put the clickLoc into sClickLoc
//put sClickLoc & return
end mouseDown
on mouseMove x, y
//if the mouse is down then put x & comma & y & return after msg
put 4 into minMove // px
if abs(item 1 of sClickLoc - x) > minMove or abs(item 2 of sClickLoc - y) > minMove then
if sLoc is not empty then
grab me
dragStart
end if
end if
end mouseMove
on mouseLeave
if the mouse is down and sLoc is not empty then
grab me
dragStart
end if
end mouseLeave
on mouseUp
if the loc of me = sLoc then
clickOnMe
else dragEnd
put empty into sLoc
put empty into sClickLoc
end mouseUp
on dragStart -- stuff to do when drag start
//show graphic r
put the seconds && "drag START" ----
end dragStart
on dragEnd -- stuff to do when drag end
//hide graphic r
put the seconds && "drag END" ----
end dragEnd
on clickOnMe
put the seconds && "CLICKED" ----
end clickOnMe
Code: Select all
local sDragging
on dragStart
put true into sDragging
end dragStart
on mouseMove
if sDragging then grab me
end mouseMove
on mouseUp
if not sDragging then
-- do click stuff
end if
put false into sDragging
end mouseUp
Code: Select all
on mouseDown
set the dragDelta to 80
grab me
end mouseDown
By typing "drag" into the dictionary search field? Or looking at the "related" entry?richmond62 wrote: ↑Fri Mar 01, 2024 9:24 amHow the fudgums is chummy, the newbie, going to find out stuff like that?
My first attempt used "set the loc of me to the mouseloc" instead of using grab, which was smooth enough on my Mac, but then I noticed that grab calculated the mouse offset automatically so I changed it.