Skip to main content
Participating Frequently
March 10, 2014
Answered

Setting opacity in a button object (InDesign CC Mac)

  • March 10, 2014
  • 2 replies
  • 1355 views

Hello everyone.

I have some code that looks like this:

  var TheButton = ThePage.buttons.add({geometricBounds:[Top, Lef, Bot, Rgt], opacity: .2, name:"EMailButton" + n});
  
    with(TheButton)
    {
       bottomLeftCornerOption  = CornerOptions.ROUNDED_CORNER;
       bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;
       topLeftCornerOption = CornerOptions.ROUNDED_CORNER;
       topRightCornerOption= CornerOptions.ROUNDED_CORNER;
      
       name  = EMailList;
       label = EMailList;
      
      fillColor = gButtonFillColor;
     

      opacity = 20;
      
       
    }

Theh problem is in the final line.  I am trying to adjust the opacity of the fill in this object but the method I am using is not working.  I have looked all over  for the correct syntax for adjusting the fill color opacity and I cannot find an example of code, nor does the documentation seem to address this issue,

Can anyone tell me how to adjust my opacity or tell me where to look for finding out that information? 

I would greatly appreciate any help this forum could give me.

R,

John

This topic has been closed for replies.
Correct answer Laubender

@John – here just an example for adding one button with transparency set to 20% in every state with some of your properties. Others set to  distinct values so that this example will work:

//Just an example:

var myButtonGeoBounds = [0,0,10,50];

var myFillColor = "Magenta";

var myButtonProperties = {

    geometricBounds: myButtonGeoBounds,

    name:"EMailButton",

    label:"EMailButton",

    bottomLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    bottomRightCornerOption:CornerOptions.ROUNDED_CORNER,

    topLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    topRightCornerOption:CornerOptions.ROUNDED_CORNER,

    fillColor: myFillColor

    };

var myNewButton = app.documents[0].pages[0].buttons.add();

myNewButton.properties = myButtonProperties;

//In case your new button will have different states and all states should have a opacity of 20%:

for(var n=0;n<myNewButton.states.length;n++){

    myNewButton.states.groups[0].transparencySettings.blendingSettings.opacity = 20;

    };

Uwe

2 replies

LaubenderCommunity ExpertCorrect answer
Community Expert
March 11, 2014

@John – here just an example for adding one button with transparency set to 20% in every state with some of your properties. Others set to  distinct values so that this example will work:

//Just an example:

var myButtonGeoBounds = [0,0,10,50];

var myFillColor = "Magenta";

var myButtonProperties = {

    geometricBounds: myButtonGeoBounds,

    name:"EMailButton",

    label:"EMailButton",

    bottomLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    bottomRightCornerOption:CornerOptions.ROUNDED_CORNER,

    topLeftCornerOption:CornerOptions.ROUNDED_CORNER,

    topRightCornerOption:CornerOptions.ROUNDED_CORNER,

    fillColor: myFillColor

    };

var myNewButton = app.documents[0].pages[0].buttons.add();

myNewButton.properties = myButtonProperties;

//In case your new button will have different states and all states should have a opacity of 20%:

for(var n=0;n<myNewButton.states.length;n++){

    myNewButton.states.groups[0].transparencySettings.blendingSettings.opacity = 20;

    };

Uwe

Trevor:
Legend
March 11, 2014

good explanation Uwe

Jump_Over
Legend
March 10, 2014

Hi,

use in this line:

//...

fillTransparencySettings.blendingSettings.opacity = 20;

//...

Jarek

Participating Frequently
March 10, 2014

Hello Jarek.  Thanks for yur reply.

I have been using this code to create the buttons:

for(var n = 0; n < EMailCount; n++)
{
    var TheButton = ThePage.buttons.add({geometricBounds:[Top, Lef, Bot, Rgt], name:"EMailButton" + n});
  
    with(TheButton)
    {
       bottomLeftCornerOption  = CornerOptions.ROUNDED_CORNER;
       bottomRightCornerOption = CornerOptions.ROUNDED_CORNER;
       topLeftCornerOption = CornerOptions.ROUNDED_CORNER;
       topRightCornerOption= CornerOptions.ROUNDED_CORNER;
      
       name  = EMailList;
       label = EMailList;
      
      fillColor = gButtonFillColor;  //  Makes the fill ccolor RGB 255,0,0,
     
     
     
      fillTransparencySettings.blendingSettings.opacity = 90; 
      //contentTransparencySettings.blendingSettings.opacity = 90;
      //transparencySettings.blendingSettings.opacity = 90;     
       
    }

Please note that I have tried fillTransparencySettings. contentTransparencySettings and transparencySettings, each by themselves and all three together and it has made no difference.  The fill color remains as ruby red as a bowl of cherries.

So I am still doing something wrong.

R,

John

Jump_Over
Legend
March 10, 2014

Hi,

right,

this line could goes like this:

groups[0].rectangles[0].fillTransparencySettings.blendingSettings.opacity = 20;

button is more complex object than regular ones...

Jarek