How do I get the object under the mouse when mouseRelease?

Dick Kriesel dick.kriesel at mail.com
Mon Apr 30 18:51:50 EDT 2007


On 4/30/07 11:30 AM, "J. Landman Gay" <jacque at hyperactivesw.com> wrote:

> If you do have to use your own handlers, then you could scan all the
> objects when the mouse goes up:
> 
> on mouseUp
>   put the mouseloc into tXY
>   repeat with x = 1 to the number of controls
>    if tXY is within the rect of control x then
>      -- do what you need
>      exit repeat
>    end if
>   end repeat
> end mouseUp
> 
> But this way can be time-consuming if you have many controls. The
> built-in commands and functions are much better.


There's another way that's fast even for many controls.  Here's a
description posted last month:


On 3/19/07 3:38 AM, "Dick Kriesel" <dick.kriesel at mail.com> wrote:

> Here's another technique for identifying the object at the mouseLoc. This
> technique is different because it works with no repeat loop, no checking the
> visible or the rect of any object, no formulas based on the mouseLoc, and no
> reference to the mouseControl.
> 
> Create a button named "mouseObject" with the following script:
> 
> -- <script>
> local sMouseObject
> 
> on mouseObject
>   if line 1 of the frontscripts is not long id of me then
>     insert script of me into front
>     lock screen
>     click at the mouseloc
>     unlock screen
>     remove script of me from front
>     return sMouseObject
>   end if
> end mouseObject
> 
> on mousedown
> end mousedown
> 
> on mouseUp
>   put long id of the target into sMouseObject
> end mouseUp
> -- <script/>
> 
> Then to test it, put the following handler into the stack script:
> 
> -- <script>
> on mouseMove
>   call "mouseObject" of button "mouseObject" of me
>   put the result
> end mouseMove
> -- <script/>
> 
> The technique passed my tests.  Does it work for you?
> 
> -- Dick





More information about the use-livecode mailing list