简体   繁体   中英

Custom ScriptUI buttons that will close the window

For those knowledgeable in ExtendScript & InDesign, I have a ScriptUI question: How can I have a window close properly after the user picks one button or the other when the buttons are custom choices . See the code below:

$.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();
    }
}

Fairly simple, no? Well, so far, the buttons don't do anything and you have to hit [ESC] in order to cancel the window. How can I get this to work?

EDIT: got the right answer:

$.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() was right. But not using it within the if(win.show() == 1)else{} block. Instead use it within the onClick function of one of the buttons.

for this you can also try getOyoWindow.hide() inside your close button.onClick function. You can also try this in your else statement. Hope this helps. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM