Skip to main content
P Harbord
Participating Frequently
March 17, 2020
Question

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

  • March 17, 2020
  • 3 replies
  • 3937 views

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?

This topic has been closed for replies.

3 replies

try67
Community Expert
March 18, 2020

(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...

JR Boulay
Community Expert
March 18, 2020

Tip!

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

😉

 

 

Acrobate du PDF, InDesigner et Photoshopographe
P Harbord
P HarbordAuthor
Participating Frequently
March 18, 2020

ah - thank you, I'll try it

Inspiring
March 17, 2020

You'd have to do it like this:

 

 

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

 

P Harbord
P HarbordAuthor
Participating Frequently
March 17, 2020

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;

  

Brainiac
March 17, 2020

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;

 


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.