Adobe ESTK取消按钮,真正取消

时间:2015-01-19 17:33:27

标签: javascript adobe extendscript cancel-button

真的那么难吗?我的谷歌是愚蠢的吗?我怎么做一个取消按钮,取消执行其余的脚本?

我的剧本很愚蠢。我不是一个好的程序员,我知道,但这就是我所拥有的:

我正在自动化INDD CScloud。脚本首先打开一个窗口,操作员有选项作为单选按钮。在底部是标准的“确定”和“取消”按钮,然后脚本有一些功能,根据窗口中显示的选项执行操作。我想要发生的是当我点击“Canel”按钮时所有代码执行停止。而已!没有什么花哨!但它似乎只是关闭对话框窗口并继续而不注册更改。 哎呀

这是我糟糕的代码:

var asker = new Window ("dialog","Answer Some Stuff!");
    var firstselector = asker.add ("panel", undefined, "Which Thing First?")
        firstselector.alignChildren = "left"
        firstselector.preferredSize = [250,100]
        thing1a = typeselector.add ("radiobutton", undefined, "Thing 1a")
        thing2a = typeselector.add ("radiobutton", undefined, "Thing 2a")
        thing3a = typeselector.add ("radiobutton", undefined, "Thing 3a")
        thing1a.value = true;
    var secondselector = asker.add ("panel", undefined, "Which Thing Second?")
        secondselector.alignChildren = "left"
        secondselector.preferredSize = [250,100]
        thing1b = secondselector.add ("radiobutton", undefined, "Thing 1b")
        thing2b = secondselector.add ("radiobutton", undefined, "Thing 2b")
        thing3b = secondselector.add ("radiobutton", undefined, "Thing 3b")
        thing1b.value = true;
    var thirdselector = asker.add ("panel", undefined, "Do Thing Three?")
        thirdselector.alignChildren = "left"
        thirdelector.preferredSize = [250,75]
        certyes = thirdselector.add ("radiobutton", undefined, "Yes")
        thidno = thirdselector.add ("radiobutton", undefined, "No")
        thirdyes.value = true;
                asker.add ("button", undefined, "Do It!", {name: "ok"});
                asker.add ("button", undefined, "Cancel", {name: "cancel"});    
asker.show();

var mainPart = function(){
if (thing1a.value == true && thing1b.value == true)
{
do some stuff
}
if (thing2a.value == true && thing1b.value == true)
{
do some different stuff
}
})();
var secondPart = function(){
if (thing3.value == true && thing1b.value == true)
{
do this other stuff
}
if (thing3.value == true && thing2b.value == true)
{
do some other stuff entirely
}
alert("All The Stuff Is Done!");
}
)();

我想要发生的是,当操作员单击“取消”按钮时,脚本将退出,mainPartsecondPart不会被执行。

我尝试使用.onClick,如下所示:

var cancelBtn = asker.add('button',undefined,'Cancel');
cancelBtn.preferredSize.width = 175;
cancelBtn.onClick=function(){
  exit();  
 }

但显然exit()无效且代码只是继续...所以我尝试break,它错误地“非法使用循环外的中断”但后来继续执行其余的反正代码...

请帮助我减少愚蠢。

1 个答案:

答案 0 :(得分:1)

Ach,你让我因你的自我贬低而笑了。

我摆脱了代码的第三部分(为了简化和停止获取错误),并修复了一个类型-o(“thirdelector”而不是“thirdselector”)。 另外,为了让事情运行起来,我在第一部分中将“typeselector”引用更改为“firstselector”。我推出了“做一些东西”的行。 然后我添加了我通常用来在我的脚本中获取取消功能的内容(“this.parent.close()”)

这是我可以用来到达你想要的地方的运行脚本。

[编辑 - 我添加了一些内容来演示如何正确地传输数据。请注意,有关取消按钮的原始问题已经得到解答。研究这个,你应该能够从中收集基本但有力的想法。]

var asker = new Window ("dialog","Answer Some Stuff!");
    var firstselector = asker.add ("panel", undefined, "Which Thing First?")
        firstselector.alignChildren = "left"
        firstselector.preferredSize = [250,100]
        thing1a = firstselector.add ("radiobutton", undefined, "Thing 1a")
        thing2a = firstselector.add ("radiobutton", undefined, "Thing 2a")
        thing3a = firstselector.add ("radiobutton", undefined, "Thing 3a")
        thing1a.value = true;
    var secondselector = asker.add ("panel", undefined, "Which Thing Second?")
        secondselector.alignChildren = "left"
        secondselector.preferredSize = [250,100]
        thing1b = secondselector.add ("radiobutton", undefined, "Thing 1b")
        thing2b = secondselector.add ("radiobutton", undefined, "Thing 2b")
        thing3b = secondselector.add ("radiobutton", undefined, "Thing 3b")
        thing1b.value = true;

   var cancelBtn = asker.add('button',undefined,'Cancel');
   var okBtn = asker.add('button',undefined,'OK');
   cancelBtn.preferredSize.width = 175;

okBtn.onClick=function(){
  mainPart();
  this.parent.close();  
 }
cancelBtn.onClick=function(){
  this.parent.close();  
 }

asker.show();

var mainPart = function(){

if (thing1a.value == true && thing1b.value == true)
{
 alert('1a and 1b');

 } else if (thing2a.value == true && thing1b.value == true) {
  alert('2a and 1b');
} else {
    alert('something else');
//do some different stuff
}
}