【问题标题】:Custom ScriptUI buttons that will close the window将关闭窗口的自定义 ScriptUI 按钮
【发布时间】:2013-06-13 15:28:43
【问题描述】:

对于那些熟悉 ExtendScript 和 InDesign 的人,我有一个 ScriptUI 问题:当用户选择一个按钮或另一个按钮后,我如何才能正确关闭窗口如果按钮是自定义选项。请看下面的代码:

$.writeln("The user pressed " + chooseOyo("123456"));

function chooseOyo(jobNumber) {
    var machine;
    var getOyoWindow = new Window ("dialog", "Which Imagesetter?");
        var textGroup = getOyoWindow.add("group");
            textGroup.orientation = "column";
            textGroup.add("statictext", undefined, "The current job is " + jobNumber);
            textGroup.add("statictext", undefined, "Please choose an imagesetter for this job:");
        var buttonGroup = getOyoWindow.add("group");
            var o1 = buttonGroup.add("button", undefined, "OYO 1");
            var o2 = buttonGroup.add("button", undefined, "OYO 2");
                o1.onClick = function () {machine = "OYO1";}
                o2.onClick = function () {machine = "OYO2";}

    if (getOyoWindow.show() == 1) {
        return machine;
    } else {
        exit();
    }
}

相当简单,不是吗?好吧,到目前为止,按钮没有做任何事情,您必须点击 [ESC] 才能取消窗口。我怎样才能让它工作?

【问题讨论】:

  • 你试过getOyoWindow.close()而不是exit吗?
  • 刚刚试了...不行。无论按下哪个按钮,窗口都会保持不变。只需按下 [ESC] 即可摆脱它并留下函数“未定义”的结果。

标签: javascript button window extendscript adobe-scriptui


【解决方案1】:

编辑:得到正确答案:

$.writeln("The user pressed " + chooseOyo("123456"));
function chooseOyo(jobNumber) {
    var machine;
    var getOyoWindow = new Window ("dialog", "Which Imagesetter?");
        var textGroup = getOyoWindow.add("group");
            textGroup.orientation = "column";
            textGroup.add("statictext", undefined, "The current job is " + jobNumber);
            textGroup.add("statictext", undefined, "Please choose an imagesetter for this job:");
        var buttonGroup = getOyoWindow.add("group");
            var o1 = buttonGroup.add("button", undefined, "OYO 1");
            var o2 = buttonGroup.add("button", undefined, "OYO 2");
                o1.onClick = function () {
                    machine = "OYO1";

                    getOyoWindow.close(); // thats the trick!

                    }
                o2.onClick = function () {
                    machine = "OYO2";
                    }
    if (getOyoWindow.show() == 1) {
    return machine;

    } else {
    return;
    }
}

close() 是对的。但不在 if(win.show() == 1)else{} 块中使用它。而是在其中一个按钮的 onClick 函数中使用它。

【讨论】:

    【解决方案2】:

    为此,您还可以在关闭 button.onClick 函数中尝试 getOyoWindow.hide()。您也可以在 else 语句中尝试此操作。 希望这可以帮助。谢谢。

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 1970-01-01
      • 2014-01-19
      • 2022-11-11
      • 2023-01-31
      • 1970-01-01
      • 1970-01-01
      • 2012-05-14
      • 1970-01-01
      相关资源
      最近更新 更多