Skip to main content
P Harbord
Participating Frequently
Mar 17, 2020 2:28 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

19 replies

try67
Community Expert
Community Expert
Mar 18, 2020 10:06 PM UTC

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

Translate
JR Boulay
Community Expert
Community Expert
Mar 18, 2020 6:59 PM UTC

Tip!

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

😉

 

 

Translate
Acrobate du PDF, InDesigner et Photoshopographe
P Harbord
P HarbordAuthor
Participating Frequently
Mar 18, 2020 7:59 PM UTC

ah - thank you, I'll try it

Translate
Inspiring
Mar 17, 2020 2:37 PM UTC

You'd have to do it like this:

 

 

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

 

Translate
P Harbord
P HarbordAuthor
Participating Frequently
Mar 17, 2020 2:48 PM UTC

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;

  

Translate
Inspiring
Mar 17, 2020 2:53 PM UTC

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

Translate