Making an image draggable

Eric Chatonet eric.chatonet at sosmartsoftware.com
Sat Jul 9 10:37:48 EDT 2005


Hi Doug,

Here is a script I use in all my plug-ins to make their window  
"draggable":

local lAllowDrag -- local variable used by all handlers in the script
---------------------------------
on mouseDown
   put the mouseH & comma & the mouseV into lAllowDrag
end mouseDown
---------------------------------
on mouseMove x,y
   if lAllowDrag is empty then exit mouseMove
   set the topLeft of this stack to globalLoc(x - item 1 of  
lAllowDrag & comma & y - item 2 of lAllowDrag)
   -- in the script of your image: set the topLeft of me to...
end mouseMove
---------------------------------
on mouseUp
   put empty into lAllowDrag
end mouseUp
---------------------------------
on mouseRelease
   put empty into lAllowDrag
end mouseRelease
---------------------------------
on mouseLeave
   put empty into lAllowDrag
end mouseLeave

BTW I think you could put your image into a sub-stack without  
decorations (same dimensions as your image): this would allow to move  
the ruler all around the screen and not only in the current window :-)
More, let the image in your main stack and use a button in the sub- 
stack the icon of which is the ID of your image: this would allow you  
to clone the sub-stack (if needed) and provide as many rulers you  
want on screen at the same time...

Le 9 juil. 05 à 16:22, Douglas Gilliland a écrit :

> I know it must be easy but I cannot figure out the script to make an
> image of a metric ruler draggable so my students can drag it around
> the screen to measure items in a quiz stack I am writing.
> Tried several variations of the following script:
> on mousedown
> make image "ruler.jpg" draggable
> end mousedown

Best Regards from Paris,

Eric Chatonet.
----------------------------------------------------------------
So Smart Software

For institutions, companies and associations
Built-to-order applications: management, multimedia, internet, etc.
Windows, Mac OS and Linux... With the French touch

Free plugins and tutorials on my website
----------------------------------------------------------------
Web site        http://www.sosmartsoftware.com/
Email        eric.chatonet at sosmartsoftware.com/
Phone        33 (0)1 43 31 77 62
Mobile        33 (0)6 20 74 50 86
----------------------------------------------------------------




More information about the use-livecode mailing list