• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Adobe JS color references - only 16 basic named colours working in my pdf

Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

I have this script setup to trigger on mouse up on a button action in my pdf

 

The objective is to cycle through 3 colours so people can mark the status of a text field Red Amber or Green (RAG)

 

This works if I hard code named colors in my events, so I thought I would do the smart thing and declare variables and setup custom colors.

 

This is not working

 

var MyCrimson = ["RGB",0.537,0.776,0];
var MyOrange = ["RGB", 0,0,1];
var MyLimegreen = ["RGB", 0,1,0];

if (color.equal(color.MyCrimson, event.target.textColor)) {
	event.target.textColor = color.MyOrange;
} else if (color.equal(color.MyOrange, event.target.textColor)) {
	event.target.textColor = color.MyLimegreen;
} else event.target.textColor = color.MyCrimson;

But this does work (just ugly colors)

if (color.equal(color.red, event.target.textColor)) {
	event.target.textColor = color.yellow;
} else if (color.equal(color.yellow, event.target.textColor)) {
	event.target.textColor = color.green;
} else event.target.textColor = color.red;

Also hard coding the "RGB" values does not work

I'm working (and previewing) on a mac - begining to think we only have the basic 16 named colors available?

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

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
LEGEND ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

You'd have to do it like this:

 

 

color.MyCrimson = ["RGB",0.537,0.776,0];
// add other colors here

 

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Thanks for answering

like this? - or hard coded in the if statement

color.MyCrimson = ["RGB",0.537,0.776,0];
color.MyOrange = ["RGB",0,0,1];
color.MyLimegreen = ["RGB",0,1,0];

if (color.equal(color.MyCrimson, event.target.textColor)) {
	event.target.textColor = color.MyOrange;
} else if (color.equal(color.MyOrange, event.target.textColor)) {
	event.target.textColor = color.MyLimegreen;
} else event.target.textColor = color.MyCrimson;

  

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
LEGEND ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Yes, that should work. You're simply adding your custom colors to the built-in color object. That orange might look blue though. :^)

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Thanks, I'll have a play

I know about the colors - choosing not to get distracted at this point

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Nearly there - thanks so much for helping

This code works just fine - cycling through Red, Blue and Green

color.MyCrimson = ["RGB",1,0,0];
color.MyOrange = ["RGB",0,0,1];
color.MyLimegreen = ["RGB",0,1,0];

if (color.equal(color.MyCrimson, event.target.textColor)) {
	event.target.textColor = color.MyOrange;
} else if (color.equal(color.MyOrange, event.target.textColor)) {
	event.target.textColor = color.MyLimegreen;
} else event.target.textColor = color.MyCrimson;

But, if I define the colors thus:

It won't change color

color.MyCrimson = ["RGB",0.761,0.035,0.173];
color.MyOrange = ["RGB",0.898,0.482,0.137];
color.MyLimegreen = ["RGB",0.494,0.694,0.173];

if (color.equal(color.MyCrimson, event.target.textColor)) {
	event.target.textColor = color.MyOrange;
} else if (color.equal(color.MyOrange, event.target.textColor)) {
	event.target.textColor = color.MyLimegreen;
} else event.target.textColor = color.MyCrimson;

 

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
LEGEND ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Generally, expecting equality for fractional values is unwise. Fractions are not stored exactly. Arithmetic is not exact for very large numbers or fractions. Either check for colours CLOSE, or set a separate variable for the colour state.

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Thanks for the reply,

I thought I was setting variables for the colours?

As you can tell script is not my strong card

 

My understanding is that I can use named colors - but this appears to only work with the original 16 netscape colors

or; use RGB, CMYK or Greyscale values between 0–1

 

Is there another way? something I'm missing

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
LEGEND ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

What you have to do is come up with custom colors that will pass the color.equal test. You can set the field color to what you want to use via the user interface, and use JavaScript to return its value, and then use those numbers in your script when adding a custom color to the color object.

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Thanks,

That's me in way over my head - I'm going to randomly adjust my values and see if I get lucky 🙂

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
LEGEND ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

Here's some more info that might make it easier. I chose an orange color for the background of a button and ran this code in the button's Mouse Up event:

 

console.println(event.target.fillColor);

console.show();

 

This printed the following on the JavaScript console:

 

RGB,0.942230224609375,0.6256103515625,0.18011474609375

 

When I added that as a custom color:

 

color.MyOrange = ["RGB", 0.942230224609375, 0.6256103515625, 0.18011474609375];

 

the result of the following was true:

 

color.equal(color.MyOrange, getField("Button1").fillColor);

 

 

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
Explorer ,
Mar 17, 2020 Mar 17, 2020

Copy link to clipboard

Copied

ah - I like it

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
Explorer ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

so, I've run the following script on 3 different colored buttons, and generated the values below

console.println(event.target.fillColor);
console.show();

 

color.MyCrimson = ["RGB",0.7607879638671875,0.0352935791015625,0.17254638671875];
color.MyOrange = ["RGB",0.942230224609375,0.6256103515625,0.18011474609375];
color.MyLimegreen = ["RGB",1,0.550994873046875,0];

if (color.equal(color.MyCrimson, event.target.textColor)) {
	event.target.textColor = color.MyOrange;
} else if (color.equal(color.MyOrange, event.target.textColor)) {
	event.target.textColor = color.MyLimegreen;
} else event.target.textColor = color.MyCrimson;

It appears to work on the first click – I'm using a button with no fill or border color, with label only (a solid circle character). This is set to white and I see it turn to MyCrimson when I click, then nothing appears to happen on subsequent clicks.

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
LEGEND ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

I strongly suggest you abandon any idea of doing comparisons on the colour. Use instead a second variable as I suggested.

if (myFieldColorSomethingOrOther == "Orange" ) {
	event.target.textColor = color.MyOrange;
        myFieldColorSomethingOrOther = "Orange" ;
} 
or whatever

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
New Here ,
Nov 29, 2021 Nov 29, 2021

Copy link to clipboard

Copied

LATEST

Hi Test Screen Name, I'm trying to do the same thing as the OP, and I'm running into the same problem. I'm with you right up until you suggest using a second variable. Can you please elaborate? What does "myFieldColorSomethingOrOther" refer to? Is this in place of using the "color.equal" comparison?

 

Thanks.

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 Expert ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Your first line is printing out the wrong color. It should be textColor, not fillColor.

If you change it you'll see that the value you apply is not exactly what it shows up as, due to the floating numbers. I would recommend you round both arrays to 2 decimal points before comparing them.

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 Expert ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

This happens due to incorrect rounding of the values in the color array.

I recommend you round both arrays (both the ones you've defined and the ones returned by textColor and/or fillColor) to 2 decimal points and then compare them.

By the way, in the first line of your code you're printing out the fillColor proeperty, but in the rest of it you're using the textColor one...

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 Expert ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

Tip!

For humans it's easier to write colors like this: ["RGB", 255/255, 141/255, 85/255]

😉

 

Capture_021.png

 

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
Explorer ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

ah - thank you, I'll try it

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 Expert ,
Mar 18, 2020 Mar 18, 2020

Copy link to clipboard

Copied

(My replies here keep disappearing for some reason... Hopefully this one will show up)

 

Your issues happen due to incorrect rounding of the values in the color array.

I recommend you round both arrays (both the ones you've defined and the ones returned by textColor and/or fillColor) to 2 decimal points and then compare them.

By the way, in the first line of your code you're printing out the fillColor property, but in the rest of it you're using the textColor one...

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