Page 1 of 1

Use the icon of button as a conditional statement (if else)?

Posted: Thu Nov 05, 2015 3:36 am
by Cheong
Dear Readers,

Is it possible to use the icon as conditional statement for if then else?

Example that I tried:

Code: Select all

if the icon of button "ButtonTest" is "TurnOn" then
  set the icon of button "ButtonTest" to "TurnOff"
end if
Am I doing this right? I still got nothing works in the statement.

Re: Use the icon of button as a conditional statement (if el

Posted: Thu Nov 05, 2015 8:10 am
by SparkOut
You can certainly do this with the icon id to refer to the it rather than a "name" as such. Otherwise you can check the button's label in that manner.

Re: Use the icon of button as a conditional statement (if el

Posted: Thu Nov 05, 2015 8:17 am
by bn
Hi Cheong,

try to identify the icon by its id as Sparkout said.

use this code as example

Code: Select all

on mouseUp
   if the icon of button "buttonTest" is the short id of image "turnOn" then
      set the icon of button "buttonTest" to the short id of image "turnOff"
   else 
      set the icon of button "buttonTest" to the short id of image "turnOn"
   end if
end mouseUp
Mind you the id of an image is the short id. This means just the number.

You can set the icon of a button by the name of the image but I don't see a way to ask for the current icon of a button by asking for the name except for using "resolve image"

Kind regards
Bernd

Re: Use the icon of button as a conditional statement (if el

Posted: Thu Nov 05, 2015 1:37 pm
by Klaus
You could also use a CHECKBOX with icons, no conditional scripting neccessary at all! :D

Re: Use the icon of button as a conditional statement (if el

Posted: Fri Nov 06, 2015 2:22 am
by Cheong
Thanks Sparkout and Bernd,

Here's the solution I done using your way:

Code: Select all

on mouseUp
   if the icon of button "ButtonTest" is the short id of image "TurnOn.png" then
     set the icon of me to "TurnOff.png"
   end if
end mouseUp
Hi Klaus, I will try it with checkbox with icons also! Thanks for the idea! :D