Page 1 of 1
toggle the text color in a field
Posted: Fri Jan 23, 2015 3:38 am
by keram
Hi,
Here is a very basic task that I want to accomplish:
Toggle the color of the text line in a field. Trying with the code below but it doesn't work.
Code: Select all
on mouseUp
if the textColor of (clickLine()) = "blue" then
set the textColor of (clickLine()) to "red"
else
set the textColor of (clickLine()) to "blue"
end if
end mouseUp
What's wrong with that code?
keram
Re: toggle the text color in a field
Posted: Fri Jan 23, 2015 5:35 am
by FourthWorld
If you check the value of the textColor you'll see that although LC allows you to use a variety of constants to assign colors, the actually stored value for colors is RGB. In the case of blue that's 0,0,255, so this change makes it work:
Code: Select all
if the textColor of (clickLine()) = "0,0,255" then
Re: toggle the text color in a field
Posted: Fri Jan 23, 2015 10:50 am
by keram
Thanks Richard,
It works OK now. Still it's surprising that I only had to change the first line, the other two with the color names remained the same and the toggling works. Also if I put this line: set textColor of fld "d" to blue into a button it will change the text color in field d. So it seems that sometimes it works with just names of colors and sometimes not.
Re: toggle the text color in a field
Posted: Fri Jan 23, 2015 11:02 am
by paul_gr
Watch out for empty lines -- If you click on an empty line you will get an error message.
That is because the clickline will not return a value.
I've added another line that will exit to top if you click on an empty line.
------------------------------------------------------------------
on mouseUp
if the value of the clickline is empty then exit to top
if the textColor of (clickLine()) = "0,0,255" then
set the textColor of (clickLine()) to "red"
else
set the textColor of (clickLine()) to "blue"
end if
end mouseUp
------------------------------------------------------------------
attached example.
Try commenting out the line I inserted and click below the bottom text on an empty line.
Paul
Re: toggle the text color in a field
Posted: Fri Jan 23, 2015 11:23 am
by keram
Thanks Paul,
It's good to know what you added.
I added 1 empty line between these 5 lines but not after the last one (yz). Then commented out your added line and still when clicking on the empty lines between the lines with the 'words' there is no error message. But clicking below the last one does create an error message (see the stack).
An additional comment to Richard's post:
If I create a field with a text in it and put this code into the field's script:
Code: Select all
on mouseUp
if the textColor of me = "blue" then
set the textColor of me to "red"
else
set the textColor of me to "blue"
end if
end mouseUp
then the toggling works OK even though I did not use the numerical values for colors. There is some inconsistency there...
keram
Re: toggle the text color in a field
Posted: Tue Jan 27, 2015 6:46 pm
by FourthWorld