STOP drag me ?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm
Contact:

STOP drag me ?

Post by pastrana » Thu Mar 04, 2010 9:40 pm

How do I make a picture "lock" into position in this script?
(I want to move the picture to the correct position and if that is true then Lock it (stop drag me command
) (the red commented script)

Thanks! Ben

SCRIPT:

global my_old_position
on mouseDown
set the layer of me to the num of controls
put the loc of me into my_old_position
grab me
end mouseDown

on mouseUp
if within (img "Yellow" ,the loc of me) then
add 1 to field "Answer"
##set the dragMove to false
else
move me to my_old_position
subtract 1 from field "Answer"
end if
end mouseUp

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4016
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: STOP drag me ?

Post by bn » Thu Mar 04, 2010 10:34 pm

Ben,
try

Code: Select all

global my_old_position
on mouseDown
   set the layer of me to the num of controls
   put the loc of me into my_old_position
   grab me
end mouseDown

on mouseUp
   if within (img "Yellow" ,the loc of me) then
      add 1 to field "Answer"
      set the loc of me to the loc of img "Yellow"  -- set the new loc
   else
      move me to my_old_position
      subtract 1 from field "Answer"
   end if
end mouseUp
regards
Bernd

pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm
Contact:

Re: STOP drag me ?

Post by pastrana » Thu Mar 04, 2010 10:41 pm

Thanks!
That works but what I want to accomplish to to disable the graphic from being moved again (drag)

Benjamin

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4016
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: STOP drag me ?

Post by bn » Fri Mar 05, 2010 12:02 am

Benjamin,
if you want to disable the drag when the object is at its final position (img "Yellow") handle that in the mouseDown handler

Code: Select all

global my_old_position
on mouseDown
   if the loc of me = the loc of img "Yellow" then exit mouseDown -- only move if not at final position
   set the layer of me to the num of controls
   put the loc of me into my_old_position
   grab me
end mouseDown

on mouseUp
   if within (img "Yellow" ,the loc of me) then
      add 1 to field "Answer"
      set the loc of me to the loc of img "Yellow"  -- set the new loc
   else
      move me to my_old_position
      subtract 1 from field "Answer"
   end if
end mouseUp
If I understand correctly what you are trying to do.
regards
Bernd

pastrana
Posts: 17
Joined: Wed Jun 14, 2006 9:54 pm
Contact:

Re: STOP drag me ?

Post by pastrana » Fri Mar 05, 2010 4:55 pm

it worked!
thanlks!

ben

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”