"mouse down" handler doesn't work as expected (should?).

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.

thanks for your suggestion Jacques,
i didn’t work for me, however.
i might have gotten it wrong, but according to ASS reference docs delta x and delta y are for getting scroll wheel values and not cursor location coordinates. maybe it needs to be used in a special way, or with coordination with other handlers…etc. if so, could you please explain?
in any case, i’ll try to explain a little more about what i’m trying to do: i have a border-less window, created with a custom class. the window itself is drag-able, as dragging is implemented in the obj-c method. however, when the window is made transparent ( again from within the method) i want to be able to drag it by holding and dragging one of its objects, (a button for ex.).
it seemed to me that connecting “mouse down” and “mouse dragged” handlers to the object, and using the “location of theEvent” property, should do it, but that didn’t work as explained above.

does anybody have an idea?

Jacques,

Thanks so much for posting this code! It helped save me a lot of time on a project I’m working on.

Macscripter’s forums have bailed me out of more jams…:smiley: