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
			
		
		
			- 
				
																			
								MarkoSato							 
									
		- Posts: 38
 		- Joined: Fri Apr 22, 2016 7:55 am
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by MarkoSato » Sun May 31, 2020 9:05 pm
			
			
			
			
			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: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » 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
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								FourthWorld							 
						- VIP Livecode Opensource Backer

 			
		- Posts: 10065
 		- Joined: Sat Apr 08, 2006 7:05 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by FourthWorld » Sun May 31, 2020 10:35 pm
			
			
			
			
			"hiliteChanged"?  Not in the v9.6 Dictionary.  Where can I learn about that message?
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Klaus							 
									
		- Posts: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » 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.
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								dunbarx							 
						- VIP Livecode Opensource Backer

 			
		- Posts: 10393
 		- Joined: Wed May 06, 2009 2:28 pm
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by dunbarx » Mon Jun 01, 2020 12:06 am
			
			
			
			
			All 
Are we sure this is about a widget? I thought it was about a button.
Craig
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								FourthWorld							 
						- VIP Livecode Opensource Backer

 			
		- Posts: 10065
 		- Joined: Sat Apr 08, 2006 7:05 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by FourthWorld » Mon Jun 01, 2020 1:40 am
			
			
			
			
			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.
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Klaus							 
									
		- Posts: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » Mon Jun 01, 2020 11:51 am
			
			
			
			
			Yes, but a "Switch Button" (widget). 

 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								MarkoSato							 
									
		- Posts: 38
 		- Joined: Fri Apr 22, 2016 7:55 am
 		
		
						
						
		
		
						
						
													
							
						
									
						Post
					
								by MarkoSato » Tue Jun 02, 2020 1:56 pm
			
			
			
			
			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") 
  
 
			
			
									
									
						 
		 
				
		
		 
	 
	
				
		
		
			- 
				
																			
								Klaus							 
									
		- Posts: 14255
 		- Joined: Sat Apr 08, 2006 8:41 am
 		
		
											
							- 
				Contact:
				
			
 
				
		
		
						
						
													
							
						
									
						Post
					
								by Klaus » Tue Jun 02, 2020 2:18 pm
			
			
			
			
			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