Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top