0

我想创建一个带有 3 个按钮的面板:

  1. 按钮 - 添加图像 1
  2. 按钮 - 添加图像 2
  3. 取消

var dlg = new Window( "dialog", "Alert Box Builder" );
dlg.btnPnl = dlg.add( "panel", undefined, "Build it" );
dlg.btnPnl.testBtn = dlg.btnPnl.add( "button", undefined, "Test" );
dlg.btnPnl.buildBtn = dlg.btnPnl.add( "button", undefined, "Build", {name: "ok" } );
dlg.btnPnl.cancelBtn = dlg.btnPnl.add( "button", undefined, "Cancel", { name: "cancel" } );
dlg.show();
4

1 回答 1

1

你在正确的轨道上!这样做只需要再添加一个按钮,然后onClick为按钮添加一个特殊功能。该函数将打开操作系统的文件浏览器,然后将文件分配给pic1Filepic2File变量。

#target photoshop
var pic1File;
var pic2File;

var dlg = new Window( "dialog", "Alert Box Builder" );
btnPnl = dlg.add( "panel", undefined, "Build it" );
pic1Btn = btnPnl.add( "button", undefined, "Image 1" );
pic2Btn = btnPnl.add( "button", undefined, "Image 2" );
buildBtn = btnPnl.add( "button", undefined, "Build", {name: "ok" } );
cancelBtn = btnPnl.add( "button", undefined, "Cancel", { name: "cancel" } );

pic1Btn.onClick = function() {
    pic1File = new File;
    pic1File = pic1File.openDlg ( "Select Background Image", "Images: *.png; *.jpeg; *.jpg" )
    if( pic1File != null ) { pic1Btn.text = File.decode ( pic1File.name ) }
    else { 
        pic1File = new File;
        pic1Btn.text = "No file selected";
    }
}

pic2Btn.onClick = function() {
    pic2File = new File;
    pic2File = pic2File.openDlg ( "Select Background Image", "Images: *.png; *.jpeg; *.jpg" )
    if( pic2File != null ) { pic2Btn.text = File.decode ( pic2File.name ) }
    else { 
        pic2File = new File;
        pic2Btn.text = "No file selected";
    }
}

dlg.show();

希望有帮助!

于 2018-02-09T23:58:28.083 回答