我具有功能,当您将值传递到其中时,当您选中“高度和宽度相同”复选框时,var constrainsProportions
启用从高度grpHeight.numb
到宽度grpWidth.numb
的对应值,反之亦然。
分别在grpWidth.numb.onChange = function()
和grpHeight.numb.onChange = function()
中调用。
而且有效。
另外,当您选中此复选框时,它将采用最高值并将其传递给第二个。
这在条件if (constrainsProportions.value == true)
中被调用
它也有效。
错误是在传递任何edittext
中的值的过程中(您未按Enter或退出编辑),您单击了复选框。它再次取最高值并将其传递给第二个。
它不起作用。任何值都不应更改。
即使当您第二次点击复选框时, constrainsProportions.value
是 false
。并且在这种情况下,不应调用grpWidth.numb.onChange()
的其他grpHeight.numb.onChange
不确定错误在哪里。
代码
#target photoshop
var mainWindow = new Window("dialog","dynamic changing values");
var grpUnitVal = mainWindow.add("group")
var constrainsProportions = grpUnitVal.add("checkbox",undefined,"Same Height and Width");
//Edittext: Height
var grpHeight = mainWindow.add("group")
grpHeight.text = grpHeight.add("statictext","Height: ");
grpHeight.numb = grpHeight.add("edittext",0);
grpHeight.numb.characters = 9;
//Edittext: Width
var grpWidth = mainWindow.add("group")
grpWidth.text = grpWidth.add("statictext","Width: ");
grpWidth.numb = grpWidth.add("edittext",0);
grpWidth.numb.characters = 9;
//Edittext: Width; if "constrains proportion" is checked,Heigth and Width values are changed in the same time
grpWidth.numb.onChange = function() {
if (constrainsProportions.value == true){
grpHeight.numb.text = grpWidth.numb.text;}
}
//Edittext: Height; if "constrains proportion" is checked,Heigth and Width values are changed in the same time
grpHeight.numb.onChange = function() {
if (constrainsProportions.value == true){
grpWidth.numb.text = grpHeight.numb.text;}
}
constrainsProportions.onClick = function() {
//Set the same heighest value in Height and Width
alert(constrainsProportions.value);
if (constrainsProportions.value == true){
if (parseInt(grpWidth.numb.text,10) > parseInt(grpHeight.numb.text,10)) {
grpWidth.numb.onChange();}
else {
grpHeight.numb.onChange();}
}
}
mainWindow.show();
谢谢。