Need help with onClick in new ExtendScript for PS.
The enclosed script was coded in ESTK for use in Photoshop. It is part of a specialized calculator to be used in PS but I can't get this starter version to work correctly. It is based on an HTML/CSS/JS version I wrote some time ago and it works correctly.
The problem I'm seeing is that the onClick code is being executed during the build but does nothing when the buttons are pressed after the dialog.show statement. You can see from the commented code that I once tried moving the onClick lines to a separate function but didn't help me.
I've tested in both ESTK and PS with the same results. I left in some alert code that shows what is happening during the build phase. It is doing what I want then not when the button is clicked.
I apprecaite any help you can supply.
Thanks,
RONC
//#script sciCALC.jsx
//#target photoshop
/**
* @@@BUILDINFO@@@ sciCalc.jsx !Version! Sat Feb 22 2020 17:24:06 GMT-0600
*/
var scriptName = "sciCALC_for_Photoshop_by_RONC ©2020";
var scriptVerNum = "0.03";
var scriptVerNumHelp = "v1";
var scriptVerDate = "22Feb2020";
var scriptVersion = scriptVerNum + " - " + scriptVerDate;
var scriptHeader = "sciCALC " + scriptVersion + " by RONC";
var scriptAuthor = ""; //"Ron Chambers";
var scriptAbstract = "sC - See Abstract and Copyright information in the HELP file: ";
var decimal = 10;
var noErr;
var slotNum, rowNum;
var dialog, dialogGraphics;
var colorBG, colorFG;
var displayArea;
var numRows = 8, numSlots = 35;
var row = [numRows], slot = [numSlots];
var keyCLEAR, keyCOPY, keyBACK, keyENTER;
var keyESC, keyESCtext, keyESCtextColor, keyESCtextGraphics;
var uiDone = 0;
doBuild();
function doBuild()
{
// dialog for calculator
dialog = new Window("dialog", " " + scriptHeader);
dialog.alignment = "center";
dialog.spacing = 1;
dialog.margins = 1;
dialogGraphics = dialog.graphics;
colorBG = [0.1, 0.1, 0.1, 1.0];
colorFG = [1.0, 1.0, 1.0, 1.0];
dialogGraphics.font = ScriptUI.newFont("ARIAL", ScriptUI.FontStyle.BOLD, 16);
dialogGraphics.backgroundColor = dialogGraphics.newBrush(dialogGraphics.BrushType.SOLID_COLOR, colorBG, 0);
dialogGraphics.foregroundColor = dialogGraphics.newPen(dialogGraphics.PenType.SOLID_COLOR, colorFG, lineWidth = 2);
// equation display area
dialog.openPnl = dialog.add("panel", undefined, scriptAuthor);
rowNum = 0;
row[rowNum] = dialog.openPnl.add("group");
row[rowNum].orientation = "row";
row[rowNum].alignment = "center";
row[rowNum].spacing = 1;
row[rowNum].margins = 1;
displayArea = row[rowNum].add('edittext {justify: "right", properties: {name: "displayArea", characters: 25}}');
displayArea.active = true;
displayArea.bounds = [0, 0, 300, 20];
displayArea.enabled = true;
displayArea.text = "0";
// calculator key area by row
rowNum++;
row[rowNum] = dialog.openPnl.add("group");
row[rowNum].orientation = "row";
row[rowNum].alignment = "center";
row[rowNum].spacing = 1;
row[rowNum].margins = 1;
row[rowNum].borderStyle='black';
slotNum = 0;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "1";
slot[slotNum].onClick = addchar("1");
slotNum++;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "2";
slot[slotNum].onClick = addchar("2");
slotNum++;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "3";
slot[slotNum].onClick = addchar("3");
slotNum++;
rowNum++;
row[rowNum] = dialog.openPnl.add("group");
row[rowNum].orientation = "row";
row[rowNum].alignment = "center";
row[rowNum].spacing = 1;
row[rowNum].margins = 1;
// operation buttons
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "CLEAR";
keyCLEAR = slot[slotNum];
slotNum++;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "BACK";
keyBACK = slot[slotNum];
slotNum++;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 60, 20];
slot[slotNum].text = "COPY";
keyCOPY = slot[slotNum];
slotNum++;
slot[slotNum] = row[rowNum].add("button");
slot[slotNum].bounds = [0, 0, 120, 20];
slot[slotNum].text = "ENTER";
keyENTER = slot[slotNum];
slotNum++;
// ESC key to close
keyESC = dialog.openPnl.add("group");
keyESC.orientation = "row";
keyESC.alignment = "center";
keyESC.spacing = 1;
keyESC.margins = 1;
keyESCtext = keyESC.add("statictext", undefined, "(ESC cancels script in PS)");
keyESCtextColor = [1.0, 1.0, 0.0, 1];
keyESCtextGraphics = keyESCtext.graphics;
keyESCtextGraphics.font = ScriptUI.newFont("ARIAL", ScriptUI.FontStyle.REGULAR, 10);
keyESCtextGraphics.foregroundColor = keyESCtextGraphics.newPen(keyESCtextGraphics.PenType.SOLID_COLOR, keyESCtextColor, lineWidth = 1);
}
doRun();
function doRun()
{
/*slotNum = 0;
slot[slotNum].onClick = addchar("1");
slotNum++;
slot[slotNum].onClick = addchar("2");
slotNum++;
slot[slotNum].onClick = addchar("3");*/
//keyCLEAR.onClick = clear();
//keyBACK.onClick = deletechar();
//keyCOPY.onClick = copy();
//keyENTER.onClick = checkValidCompute();
//dialog.cancelElement = null;
//dialog.defaultElement = null;
dialog.show();
}
function doDone()
{
alert(displayArea.text, "OK");
dialog.close();
}
function addchar(charIn)// add char
{
alert(displayArea.text + " " + charIn, "addc1");
if (displayArea.text === "" || displayArea.text === "0")
displayArea.text = charIn;
else
displayArea.text += charIn;
alert(displayArea.text + " " + charIn, "addc2");
}
//
//============================== sciCALC =====================
//
function sciCALC()
{
sciCALC.main = function ()
{
if (uiDone !== 0)
{
alert("ABORTING due to ERROR", "sciCALC ERROR");
}
else
{
sciCALC();
}
sciCALC.main();
};
}
"sciCALC.jsx";
// EOF
