如果从内部onclick()调用app.open没有响应

时间:2015-03-21 17:31:45

标签: javascript onclick adobe-indesign

使用InDesign的脚本我发现了这个问题:如果我从button.onclick()内部调用app.open()它会停止并且没有任何反应。 由于我是Javascript的初学者,我可能做错了。但如果没有,我该如何解决?我找不到另类选择。

请,只有纯Javascript。

提前致谢。

这是工作代码:

var book_info;

if (app.books.length != 1) {
    var theFile = File.openDialog ("Select the book file to open...");
    get_data(theFile);
        alert(book_info.filePath + "\r" + book_info.name);
}

book_info.close();

    function get_data(data) {
        app.open(data);
        book_info = app.activeBook;
            alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
        return data;
    }

这里没有工作:

var book_info;

var w1 = new Window ("dialog", "TEST");
    w1.minimumSize.height = 50;
    w1.minimumSize.width = 50;

var p1 = w1.add ("panel");
        sel_button = p1.add ("button", undefined, "Select book");

var g1 = w1.add ("group");
        g1.add("button", undefined, "Cancel");
        g1.add("button", undefined, "OK");

sel_button.onClick = function(){
    var theFile = File.openDialog ("Select the book file to open...");
    get_data(theFile);
        alert(book_info.filePath + "\r" + book_info.name);
    book_info.close();
};

w1.show();


function get_data(data) {
    app.open(data);
    book_info = app.activeBook;
        alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);
    return data;
}

1 个答案:

答案 0 :(得分:0)

app.open not responding if called from inside onclick()

还有另一种答案

它还建议使用' palette'窗口而不是模态对话

试试这个:

var book_info;     
var theFile;   
var getData;  
var w1 = new Window ("dialog", "TEST");     
    w1.minimumSize.height = 50;     
    w1.minimumSize.width = 50;     
    var p1 = w1.add ("panel");     
        sel_button = p1.add ("button", undefined, "Open a book");     
    var g1 = w1.add ("group");     
        g1.add("button", undefined, "Cancel");     
        g1.add("button", undefined, "OK");     

sel_button.onClick = function(){     
    theFile = File.openDialog ("Select the book file to open...");    
  getData =1;           
  w1.close(1);   
};     

w1.show()  

if (  getData ==1) {   
  if ( theFile ) {   
  get_data(theFile);     
  }   
}   

function get_data(data) {     
    app.open(data);     
    book_info = app.activeBook;     
        alert("INSIDE FUNCTION" + book_info.filePath + "\r" + book_info.name);     
    return data;     
}