hi everyone,
i’m having problems trying to implement “mouse down” and “mouse dragged” handles to determine cursor location. i’ve found this code by Jobu, which supposed to change the location of an object, according to the mouse cursor location (dragging), it was posted some 2 years ago, so maybe things have changed since:
property diffX : 0
property diffY : 0
on mouse dragged theObject event theEvent
set {dragX, dragY} to location of theEvent
set adjX to (dragX - diffX)
set adjY to (dragY - diffY)
tell window "theWindow"
tell button "theButton"
set position to {adjX, adjY}
end tell
(* Also drag optional secondary objects *)
--> Assumes same dimensions as button
--tell image view "theImage"
--set position to {adjX, adjY}
--end tell
end tell
end mouse dragged
on mouse down theObject event theEvent
if name of theObject is "theButton" then
set {downX, downY} to location of theEvent
set {objX, objY} to position of theObject
set diffX to (downX - objX)
set diffY to (downY - objY)
end if
end mouse down
this code doesn’t work for me, and as far as i can tell, the reason is this:
the “location of TheEvent” property for both the “mouse down” and “mouse dragged” handlers always return the same values, which are the {left, bottom} coordinates of the window that the button is in, instead of the cursor location.
to be clearer: {downX, downY} and {dragX, dragY} of the code above always return the same values, no matter where inside the button i click or drag.
the documentation for “location” property sheds very little light on the subject…
what am i missing?
how do you obtain information on the cursor location using “mouse down” (or dragged)?
thanks.