Click once do something, click again do something else?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Click once do something, click again do something else?

Post by TodayIsTheDay » Mon Sep 14, 2009 4:21 pm

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!

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Mon Sep 14, 2009 5:05 pm

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

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Mon Sep 14, 2009 5:38 pm

Thanks! That did exactly what I needed!

Post Reply