Swtich Button toggle

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Swtich Button toggle

Post by MarkoSato »

Hello,

when i click a button I want to show and hide an image. I have this code:

Code: Select all

set the Hilite of the Target to not the Hilite of the Target
   if the Hilite of the Target = true
   then
      set the visible of img "image.png" to true
   else
      set the visible of img "image.png" to false
   end if
and i have "hide img "image.png" on the card script, so that the image is first not visible.

it works finde but I have this little problem. On the first click nothing happens but after the second click every click toggles between hiding and showing the image. I would like the first click directly to show the image. Can someone help? Thanks

Best
Marko
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Swtich Button toggle

Post by Klaus »

Hi Marko,

so you have a "switch button" for this?
Then you need to script: on hiliteChanged, just in case you didn't.

And this one-liner will do what you need:

Code: Select all

on hiliteChanged
   ## Thanks to Mr. Boole we can:
   set the visible of img "image.png" to the hilite of me
end hiliteChanged
:-)


Best

Klaus
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Swtich Button toggle

Post by FourthWorld »

"hiliteChanged"? Not in the v9.6 Dictionary. Where can I learn about that message?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Swtich Button toggle

Post by Klaus »

Well, that is the message sent to widget "Switch Button", and also to these widgets:
Navigation bar
Treeview
Segmented Control
:-)
I see this in the dictionary of 9.5.1, did not try 9.6 yet.

Create a "Switch button", open its script editor and you will see it on the left side
as the only entry in the build-in handler list.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Swtich Button toggle

Post by dunbarx »

All

Are we sure this is about a widget? I thought it was about a button.

Craig
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Swtich Button toggle

Post by FourthWorld »

Klaus wrote: Sun May 31, 2020 11:15 pm Well, that is the message sent to widget "Switch Button", and also to these widgets:
Navigation bar
Treeview
Segmented Control
:-)
I see this in the dictionary of 9.5.1, did not try 9.6 yet.

Create a "Switch button", open its script editor and you will see it on the left side
as the only entry in the build-in handler list.
Thanks, Klaus. I had my Dict open to the "LiveCode Script" default; like Craig, I had thought the question here was about a button.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Swtich Button toggle

Post by Klaus »

Yes, but a "Switch Button" (widget). :-D
MarkoSato
Posts: 38
Joined: Fri Apr 22, 2016 7:55 am

Re: Swtich Button toggle

Post by MarkoSato »

Klaus wrote: Sun May 31, 2020 9:31 pm Hi Marko,

so you have a "switch button" for this?
Then you need to script: on hiliteChanged, just in case you didn't.

And this one-liner will do what you need:

Code: Select all

on hiliteChanged
   ## Thanks to Mr. Boole we can:
   set the visible of img "image.png" to the hilite of me
end hiliteChanged
:-)


Best

Klaus
Hey, sry my bad for not knowing the right terms. No, I have a normal button (I didn't know there is a thing like "switch button") :oops: :oops:
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Swtich Button toggle

Post by Klaus »

Hola Marko,

OK, but only a RADIOBUTTON or a CHECKBOX has a (permanent) hilite property.
So what do you mean with -> ...the hilite of the target?
Or did you uncheck the "autohilite" property of your (normal) button?


Best

Klaus
Post Reply