Page 1 of 1

Get the name of intersecting button

Posted: Wed Mar 05, 2014 11:25 pm
by KennyR
I am wondering how to get the name of the button that is being intersected when doing a drag operation.... so for instance... You have 5 buttons in a group and each button has a grab command in the mouseDown handler, how can I determine which button the dragged button is colliding with? I understand using the intersect command works when naming a particular button, but when there are multiple buttons on a screen, it seems labor intensive to list all possible intersect scenarios. Thanks for the help...

Re: Get the name of intersecting button

Posted: Thu Mar 06, 2014 2:00 am
by KennyR
well I am getting good at answering my own questions.... :D

Code: Select all

global vOldLoc
on mouseUp
   repeat with x=1 to the number of btns on this cd
      
      if the intersect(me,btn x) then 
         put the short name of btn x  into vName
         put the loc of btn x  into vLoc
           move me to vLoc in 10 ticks
        exit repeat
        
      else
         end if
      end repeat
    
       move btn vName to vOldLoc in 10 ticks
end mouseUp

on mouseDown
   grab me
   set the layer of me to top
   put the loc of me into vOldLoc
end mouseDown

on mouseStillDown
      set the ink of me to srcOrReverse
end mouseStillDown

Re: Get the name of intersecting button

Posted: Thu Mar 06, 2014 2:47 pm
by Klaus
What Kenny said! :D

Hint: "mosuestilldown" is a bit CPU intensive and since you do not set the INK back somewhere,
it might be a good idea to only set the INK once on mousedown:

Code: Select all

global vOldLoc
on mouseUp
   repeat with x=1 to the number of btns on this cd
      
      if the intersect(me,btn x) then 
         put the short name of btn x  into vName
         put the loc of btn x  into vLoc
         move me to vLoc in 10 ticks
         exit repeat
        
      ## Really no empty ELSE case neccesary 8-)
      end if
      end repeat 
      move btn vName to vOldLoc in 10 ticks
end mouseUp

on mouseDown
   grab me
   set the ink of me to srcOrReverse
   set the layer of me to top
   put the loc of me into vOldLoc
end mouseDown

## Look ma, no "mousestilldown" :-)
Best

Klaus