Changing a Button Colour

Community Beginner ,
Mar 25, 2021 Mar 25, 2021

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.

TOPICS
How to

Views

371

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Mar 25, 2021 Mar 25, 2021
Use this:event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;

Likes

Translate

Translate
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

As "Mouse UP" event of button use this code:

event.target.fillColor = color.red;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Most Valuable Participant ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Do you mean toggle its color with each click?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Yep

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Use this:

event.target.fillColor = (color.equal(color.white, event.target.fillColor)) ? color.red : color.white;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Is there a place/list where I can find out what colors are available to choose from?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 26, 2021 Mar 26, 2021

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]

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2021 Mar 26, 2021

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?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

There is lots of sites where you can get RGB codes like this one:

https://htmlcolorcodes.com/ 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 26, 2021 Mar 26, 2021

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;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Mar 26, 2021 Mar 26, 2021

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];

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

LATEST

Most helpful, and very much appreciated.  Thank you.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines