Copy link to clipboard
Copied
var Int_Mod = this.getField("INT_Total");
var button_color = this.getField("01").fillColor;
if (button_color.toString() == ["RGB", 1, 1, 1])
{
app.alert("Switch color to Grey, +1 to INT Modifiers");
Int_Mod.value = (this.getField("INT_Total").value - 1);
this.getField("01").fillColor = ["RGB", .5 ,.5 ,.5 ];
}
else if (button_color.toString() == ["RGB", .5, .5, .5] )
{
app.alert("Switch color to Red, +5 to INT Modifiers");
Int_Mod.value = (this.getField("INT_Total").value - 4);
this.getField("01").fillColor = ["RGB", 1, 0, 0 ];
}
else if (button_color.toString() == ["RGB",1, 0, 0])
{
app.alert("Switch color to Black, set INT Modifier to 0");
Int_Mod.value = (this.getField("INT_Total").value + 5);
this.getField("01").fillColor = ["RGB", 0, 0, 0 ];
}
else if (button_color.toString() == ["RGB", 0, 0, 0] )
{
app.alert("Switch color to White, 0 INT Modifiers");
this.getField("01").fillColor = ["RGB", 1, 1, 1];
}
else
{
this.getField("01").fillColor = ["RGB",1,1,1] // in case color is not white when button created
app.alert("default to white")
}
I need about 20 buttons with this code in the Mouse Up Event. Each button will affect one text field. I'm wondering if there is a better way to do this, maybe a switch/case? I don't want to cut/paste/edit the code for each button.
Thank you for looking at this.
Copy link to clipboard
Copied
Use a document-level function with args for the field names. Call this function at every button.
Copy link to clipboard
Copied
Can you give me an example. I'm not really a programmer, I'm just trying to figure this out.
Copy link to clipboard
Copied
Examples of JavaScript functions:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now