Page 1 of 1

STOP drag me ?

Posted: Thu Mar 04, 2010 9:40 pm
by pastrana
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

Re: STOP drag me ?

Posted: Thu Mar 04, 2010 10:34 pm
by bn
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

Re: STOP drag me ?

Posted: Thu Mar 04, 2010 10:41 pm
by pastrana
Thanks!
That works but what I want to accomplish to to disable the graphic from being moved again (drag)

Benjamin

Re: STOP drag me ?

Posted: Fri Mar 05, 2010 12:02 am
by bn
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

Re: STOP drag me ?

Posted: Fri Mar 05, 2010 4:55 pm
by pastrana
it worked!
thanlks!

ben