3 Replies Latest reply on Jan 5, 2016 1:36 AM by George_Johnson

    Define rgb colour

    sp3shalpdfs

      Hello,

       

      i am using fillColor to color a combo box based on value, my code is below:

       

      color.orange = ["RGB", 1, .33, 0];

      if (event.value=="Low (4)") event.target.fillColor = color.green;

      else if (event.value=="Low (4)") event.target.fillColor = color.green;

      else if (event.value=="Low (8)") event.target.fillColor = color.green;

      else if (event.value=="Low (12)") event.target.fillColor = color.green;

      else if (event.value=="Low (16)") event.target.fillColor = color.green;

      else if (event.value=="Low (20)") event.target.fillColor = color.green;

      else if (event.value=="Low (24)") event.target.fillColor = color.green;

      else if (event.value=="Low (28)") event.target.fillColor = color.green;

      else if (event.value=="Low (32)") event.target.fillColor = color.green;

      else if (event.value=="Low (36)") event.target.fillColor = color.green;

      else if (event.value=="Low (60)") event.target.fillColor = color.green;

      else if (event.value=="Medium (40)") event.target.fillColor = color.yellow;

      else if (event.value=="Medium (44)") event.target.fillColor = color.yellow;

      else if (event.value=="Medium (52)") event.target.fillColor = color.yellow;

      else if (event.value=="Medium (64)") event.target.fillColor = color.yellow;

      else if (event.value=="Medium (68)") event.target.fillColor = color.yellow;

      else if (event.value=="High (48)") event.target.fillColor = color.orange;

      else if (event.value=="High (56)") event.target.fillColor = color.orange;

      else if (event.value=="High (76)") event.target.fillColor = color.orange;

      else if (event.value=="High (88)") event.target.fillColor = color.orange;

      else if (event.value=="Critical (72)") event.target.fillColor = color.red;

      else if (event.value=="Critical (80)") event.target.fillColor = color.red;

      else if (event.value=="Critical (92)") event.target.fillColor = color.red;

      else if (event.value=="Critical (84)") event.target.fillColor = color.red;

      else if (event.value=="Critical (96)") event.target.fillColor = color.red;

      else if (event.value=="Critical (100)") event.target.fillColor = color.red;

      else event.target.fillColor = color.white;

       

      What im trying to do is define other rgb colors:

          color.red = ["RGB", 254, 0, 0];

          color.green = new color ["RGB", 255, 0, 255];

          color.yellow = ["RGB", 255, 255, 1];

       

      But when i add the above with the rest of my code it breaks and no colors work.

       

      Plus im not sure what 1,.33,1 is or how it relates to rgb as i cant get that variation to work in any online rgb  display tool.

       

      Can anyone help?

        • 1. Re: Define rgb colour
          Test Screen Name Most Valuable Participant

          JavaScript does not use colours in the range 0 to 255. You need to understand what something like 0,128,255 actually means, so you can translate it to the form needed as described in the docs. do you have the API document?

          • 2. Re: Define rgb colour
            try67 MVP & Adobe Community Professional

            The values the color object expects should range from 0 to 1. So if you want to use the more common 0-255 values just divide them by 255 and you'll get the same results.

            • 3. Re: Define rgb colour
              George_Johnson MVP & Adobe Community Professional

              Also, the following isn't correct, even if you used the correct numbers:

               

              color.green = new color ["RGB", 255, 0, 255];


              To replace the old value with a new one, you'd do this:


              color.green = ["RGB", 1, 0, 1];


              This will change the built-in color green until Acrobat/Reader is restarted. To create a new color as a property of the built-in color object, you'd do something like:


              color.new_green = ["RGB", 0, 128/255, 1];


              You can also simply set a variable to a color array:


              var green1 = ["RGB", 0, 128/255, 0];

              event.target.fillColor = green1;


              which is what I'd recommend you do.