Buttons and the clickLoc

Date:    Wed, 13 Sep 1995 09:27:02 -0500
From:    "Dan L. Berlyoung" <1dan@IONET.NET>
Subject: button scripts and clickLoc
I just learned something that I thought the rest of the dirct-l'ers out there might benifit from.

Occasionally I'm short of sprites and I'll have one button do the work of many. I just check where in the button the mouse is and then act accordingly. Like this,

on mouseUp
   if the mouseV > 100 then
        --do something
   else
        --do something else
   end if
end
But I started seeing a problem with this running on slower systems. If you clicked on the button and quickly moved the mouse to another part of the button, by the time the script got to checking the mouseV it was incorrect. On faster systems the time between the click and the mouseV was insignificant, but on slower systems it can be enormous.

So I remembered the clickLoc function. It returns the location of the last mouse click! Wowee! I changed my script to the following and all was right with the world again. (Remember, the clickLoc returns a point and the getAt function just extracts the x (1) or y (2) coordiante.)

on mouseUp
   if getAt( the clickLoc, 2 ) > 100 then
        --do something
   else
        --do something else
   end if
end