Page 1 of 1

2-state button

Posted: Mon Jul 04, 2011 4:26 pm
by gjtaylor99
Hi, I'm a newbie, just off the 2011 Summer Academy.

I've been following the BYU tutorials, and have got to a point where I want to create a 2-state button, e.g. Record/Stop recording, where the same button will switch dynamically to its opposite function, e.g. if it's recording, it will show Stop recording, and vice versa.

I'm thinking it must be a very commonly used routine, (and I don't want to waste time needlessly re-inventing existing wheels) but I can't seem to find a standard routine for this anywhere online. Anyone got the code for this, or is it something I should work it out for myself?

Cheers

Re: 2-state button

Posted: Mon Jul 04, 2011 4:41 pm
by Klaus
Hi gjtaylor99,

you will need to check and set "the label" of the button like this:

Code: Select all

on mouseup
   if the label of me = "Start" then
      set the label of me to "Stop"
     ###  start your recording here...

   else
    set the label of me to "Start"
    ## stop recording here and now
  end if
end mouseup
You could also change the ICON accordingly if necessary.
You get the picture.


Best

Klaus

Re: 2-state button

Posted: Mon Jul 04, 2011 4:59 pm
by gjtaylor99
Klaus wrote:

Code: Select all

on mouseup
   if the label of me = "Start" then
      set the label of me to "Stop"
     ###  start your recording here...
   else
    set the label of me to "Start"
    ## stop recording here and now
  end if
end mouseup
You get the picture.
Wow, I suspected it was something like that, but then went off into unnecessary complications. Your solution is so clean and simple! Thanks a lot.
Geoff

Re: 2-state button

Posted: Tue Jul 05, 2011 5:43 pm
by dunbarx
Keep asking.

LC is built in such a way so that many solutions are just that compact and beautiful. It is the structure of the language that makes it so.

Keep asking.

Craig Newman