This should be simple: drag an object

Dear co-scripters.
This is what I want to establish:
I have an Image View on a Window, and I want the user of my app to be able to drag that image view (which contains an image) around the window.
I looked at the Mousedragged command, but I don’t understand the syntax. Even a simple

on mouse dragged theObject event theEvent
	log "something should happen now"
end mouse dragged

doesn’t do anything, although I connected the ImageView to the script containing this command, and checked the MouseDragged check box.

If I get that to work, I’m still worried about getting the mouse coordinates (how?), and adding/subtracting them from the position of the ImageView, with the aim to do a ‘live’ dragging of the image view, rather than moving the image view only on a mouseUp.

I would be extremely grateful for any help
Best regards


Well, thank you all for your tremendous support.
Since I haven’t figure out to catch the MouseDragged event through an Image View, I just put a transparent Box on top of it, that actually WAS able to receive the MouseDragged event.
But I’m not discouraged at all. I guess you guys are really busy. Or I’m just SO stupid that nobody cares to respond.
After this, I will post yet another fascinating question. Let’s see how many replies that will yield.

You should not overlap Cocoa views. It may lead to undefined redraw, responder, and performance behaviour.

I would recommend comparing what you’re trying to do with the Apple-provided dragging example. Additionally, the archives here have answered similar questions many times. Search is your friend!

No need to be sarcastic after not getting an answer in a few hours…

But still, I’d like to learn about this too, and I’ve searched and come up with nothing. The mousedragged is not what i tried with but just the “on drag” handler. An object in a window should be possible to drag and then drop on another object, right? What’s the magic? Nothing in the Apple example project does this, only drag from the finder no drag within the app.

I’d like to drag a button or an image to another button and then execute something. Is this possible without cocoa?


Is this the answer?

Not supported (through AppleScript Studio version 1.4).

Support for this event handler is planned for a later version of AppleScript Studio.