Page 1 of 1

Click once do something, click again do something else?

Posted: Mon Sep 14, 2009 4:21 pm
by TodayIsTheDay
How can I make a button do something when I click it one, then do something else when I click it again. Like show something, not show something?

Would this be better done with a checkbox? (I figured out the code to do it that way)

Thanks!

Posted: Mon Sep 14, 2009 5:05 pm
by SparkOut
Odd as it sounds, a checkbox is (as far as RunRev is concerned) a button.
So the way to do it with a "normal" button is pretty similar. With a checkbox the hilited property is a handy built-in that can be used to give visible feedback of the state, and be checked for the condition to tell what to do whether true or false.
If you want to do this with a custom button you can do something like (and there are many ways to skin the RunRev cat):

Code: Select all

on mouseUp
  set the uFlag of me to not the uFlag of me
  -- toggles the custom property "uFlag" to be the opposite of the true or false condition it currently is
  switch the uFlag of me
    case true
      --do stuff (maybe change the label of me, or visual appearance too)
      break
    case false
      --do other stuff (maybe change the label of me, or visual appearance too)
      break
  end switch
end mouseUp
(Untested - check for typos!)
HTH,
SparkOut

Posted: Mon Sep 14, 2009 5:38 pm
by TodayIsTheDay
Thanks! That did exactly what I needed!