messages to buttons when the mouse is already down

Michael J. Lew michaell at unimelb.edu.au
Tue Jan 22 17:39:01 EST 2002


Thanks for all of the helpful suggestions. It is a more interesting 
exercise than I expected in that the messages that one might expect 
to use are blocked when the mouse is down. Perhaps they shouldn't 
be...

The following won't work because the target is the control that gets 
the mouseDown message and so target-ness doesn't follow the mouseloc.

>on mouseEnter -- you can put the rest of this in an offscreen handler
>   repeat until the mouseClick
>     if the mouseLoc is within the rect of the target then
>       set the hilite of the target to true
>   else
>       set the hilite of the target to false
>   end if
>   -- do your thing here when the mouse is released
>end mouseEnter

The following does work, but as someone else suggested, I do have 
lots of buttons (225) and so it is doing a lot of work.

>on mouseDown
>   repeat while the mouse is down
>     get the mouseLoc
>     repeat with n = 1 to the number of btns
>       if it is within the rect of btn n then
>         set the hilite of btn n to true
>       else
>         set the hilite of btn n to false
>       end if
>     end repeat
>   end repeat
>end mouseDown

The following doesn't work because, again, the control that gets the 
mouseDown is the only one to get the mouseEnter and mouseLeave 
messages. Remember that I would like to be able to click in the array 
of buttons and drag, with the hilight leaving a trail showing the 
path of the dragging.

on mouseEnter
    if word 1 of the target = "button" then
      set the hilite of the target to true
    end if
end mouseEnter

on mouseLeave
    if word 1 of the target = "button" then
      set the hilite of the target to false
    end if
end mouseLeave

The suggestions of working out a quick equation that translates the 
mouseLoc into a button number should work. I guess I'll have to put 
it into a mouseDown handler either in all of the buttons or in the 
group containing the buttons. I can't fully test it at the moment 
because the stack is a game that I am writing for my son and so I am 
doing it at home, and it is work-time here down under at the moment.

Thanks to Ken, David and Terry for your helpful suggestions. I have 
not responded earlier because I take the digest and I try to sleep at 
night!
-- 
Michael J. Lew

Senior Lecturer
Department of Pharmacology
The University of Melbourne
Parkville 3010
Victoria
Australia

Phone +613 8344 8304

**
New email address: michaell at unimelb.edu.au
**



More information about the Use-livecode mailing list