Testing if the mouse clicked on ME (button)?!
Eric Chatonet
eric.chatonet at sosmartsoftware.com
Sat Aug 9 11:36:29 EDT 2008
Bonjour Heather,
It's not as simple as it seems :-)
There are many problems to solve here:
I am clicked??, a wait that will hang Rev, etc.
All this is a good reason to choose another architecture using the
'send <in time>' command.
To get you started:
local lCancelID -- script local variable
constant kTimerDelay = 1 -- constant
------------------------------
on mouseUp
if the label of me is "Start" then
put 0 into fld "Counter Show"
set the label of me to "Stop"
send "SetTimer true" to me in kTimerDelay second --
else
put empty into fld "Counter Show"
set the label of me to "Start"
SetTimer false --
end if
end mouseUp
------------------------------
on SetTimer pFlag
if pFlag then -- starts timer
add 1 to fld "Counter Show"
if "SetTimer" is not in the pendingMessages then
-- to avoid having a double pending message
send "SetTimer true" to me in kTimerDelay second --
end if
put the result into lCancelID
else -- stops timer by canceling pending message
cancel lCancelID
end if
end SetTimer
See 'send', 'cancel' and 'pendingMessages' in the docs :-)
Le 9 août 08 à 16:19, H Baric a écrit :
> Ugh. Sorry for another probably easy/obvious one to you clever
> folk, but I
> can't seem to work out how to do this (and probably shouldn't be at
> this
> time as I'm just about falling asleep, but it's driving me crazy as
> it was
> supposed to be a quick simple thing to do):
>
> Making a timer, with just one button and one field.
> The one button is to start and stop the timer.
> The button's label is changed to "Stop" when it starts, and "Start"
> when it
> stops. I think I got that?
> But, how to test when the user clicks on the button during the
> process?
> (sorry, hey don't laugh! I have been searching and trying
> everything I know,
> which isn't much yet!)
>
> But it's simple right? *blush*
>
> Here goes:
>
> on mouseUp
> if the label of me is "Start" then
> set the label of me to "Stop"
> repeat with tCount = 1 to 60
> put tCount into fld "Counter Show"
> wait 1 second
> if (I am clicked??) and the label of me is "Stop" then
> exit repeat
> set the label of me to "Start"
> end if
> end repeat
> end if
> end mouseUp
>
> Cheers,
> Heather - Who's toddler and teenager messed with most of her brain
> cells
> today.
More information about the use-livecode
mailing list