Copy link to clipboard
Copied
Is it possible to change the color of a button once it has been pressed? Say, from white to red.
Use this:
event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;
Copy link to clipboard
Copied
As "Mouse UP" event of button use this code:
event.target.fillColor = color.red;
Copy link to clipboard
Copied
That's brilliant! Thank you. Final question, is it possible to deselect the button so that it returns to it's initial color?
Copy link to clipboard
Copied
Do you mean toggle its color with each click?
Copy link to clipboard
Copied
Yep
Copy link to clipboard
Copied
Use this:
event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;
Copy link to clipboard
Copied
Is there a place/list where I can find out what colors are available to choose from?
Copy link to clipboard
Copied
Like this 'color. ' you can only use these colors:
red,green,blue,cyan,magenta,yellow,white,black,transparent.
But you can use any color using either RGB codes or CMYK.
As example Il use RGB colors, for black,white and transparent you can also use like this:
transparent - ["T"]
this.getField("Text1").fillColor = ["T"];
Black - ["G",0]
White - ["G",1]
and any shades of grey between black and white ["G",0.1] ["G",0.2]...
For RGB colors you can use like this:
lets say dark green color RGB code is 0 82 33 you divide each number with 255
0 is 0, 82 is 0.32 and 33 is 0.12 so the code would be ["RGB", 0,0.32,0.12]
or you can also use it like this:
["RGB", 0/255,82/255,33/255]
Copy link to clipboard
Copied
Hi Nesa,
Thank for that. I've almost got it. How do I substitute the dark green to say the red or white from what you've said above?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Sorry, I ment how to I write the correct code to subsitute say the dark green (or any other RGB) in the script you provided below?
event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;
Copy link to clipboard
Copied
Replace color.red with ["RGB", 0/255,82/255,33/255]
EDIT: full code would be:
event.target.fillColor = (color.equal(["RGB", 255/255,255/255,255/255], event.target.fillColor)) ? ["RGB", 255/255,0/255,0/255] : ["RGB", 255/255,255/255,255/255];
Or
event.target.fillColor = (color.equal(["RGB", 1,1,1], event.target.fillColor)) ? ["RGB", 1,0,0] : ["RGB", 1,1,1];
Copy link to clipboard
Copied
Most helpful, and very much appreciated. Thank you.
Copy link to clipboard
Copied
Can we use the button to change the color of a shape with the above code?