2010-03-01 7 views
1

대화 상자를 그리는 JavaScript 함수가 있습니다. 나는 그것이 사용자가 지정한 값을 반환하도록하고 싶습니다. 문제는 사용자가 onClick 이벤트가 할당 된 두 개의 버튼을 클릭하면 대화 상자가 닫히는 것입니다. 이러한 이벤트를 잡는 유일한 방법은 해당 함수에 함수를 할당하는 것입니다. 즉, return 함수는 내 inputDialog 함수가 아니라 지정된 함수를 반환합니다. 나는 어리석은 방법으로 이것을하고 있다고 확신한다.JavaScript 대화 상자가 반환됩니다.

궁금한 점이 있으시면,이 스크립트는 Adobe의 ExtendScript API를 사용하여 After Effects를 확장하고 있습니다. 나는 해결책을 마련했습니다

function inputDialog (queryString, title){ 
    // Create a window of type dialog. 
    var dia = new Window("dialog", title, [100,100,330,200]); // bounds = [left, top, right, bottom] 
    this.windowRef = dia; 

    // Add the components, a label, two buttons and input 
    dia.label = dia.add("statictext", [20, 10, 210, 30]); 
    dia.label.text = queryString; 
    dia.input = dia.add("edittext", [20, 30, 210, 50]); 
    dia.input.textselection = "New Selection"; 
    dia.input.active = true; 
    dia.okBtn = dia.add("button", [20,65,105,85], "OK"); 
    dia.cancelBtn = dia.add("button", [120, 65, 210, 85], "Cancel"); 


    // Register event listeners that define the button behavior 

    //user clicked OK 
    dia.okBtn.onClick = function() { 
     if(dia.input.text != "") { //check that the text input wasn't empty 
      var result = dia.input.text; 
      dia.close(); //close the window 
      if(debug) alert(result); 
      return result; 
     } else { //the text box is blank 
      alert("Please enter a value."); //don't close the window, ask the user to enter something 
     } 
    }; 

    //user clicked Cancel 
    dia.cancelBtn.onClick = function() { 
     dia.close(); 
     if(debug) alert("dialog cancelled"); 
     return false; 
    }; 

    // Display the window 
    dia.show(); 

} 

답변

0

:

여기에 코드입니다. 정말 못 생겼지 만 지금은 나를 잠잠 케 하겠어 ... 누구나 더 나은 해결책이 있을까요?

var ret = null; 

    // Register event listeners that define the button behavior 
    dia.okBtn.onClick = function() { 
     if(dia.input.text != "") { //check that the text input wasn't empty 
      var result = dia.input.text; 
      dia.close(); //close the window 
      if(debug) alert(result); 
      ret = result; 
      return result; 
     } else { //the text box is blank 
      alert("Please enter a value."); //don't close the window, ask the user to enter something 
     } 
    }; 

    dia.cancelBtn.onClick = function() { //user cancelled action 
     dia.close(); 
     ret = false; 
     return false; 
    }; 

    // Display the window 
    dia.show(); 

    while(ret == null){}; 
    return ret; 
관련 문제