OnClick function is not run?

Photoshop Script Snippets - Note: Full Scripts go in the Photoshop Scripts Forum

Moderators: Tom, Kukurykus

unpradise

OnClick function is not run?

Post by unpradise »

HI everyone,

I am new to JavaScript scripting in Photoshop. I am using CS5 and need to create a small tool with a user interface. I found CS2's Script UI document after Googled on the Internet and hacked together this code below. However, then I text it using CS5 on Windows and Mac, it does not work. The UI is correctly drew on the screen. But when I click on the
"Create" button, nothing happens.

I couldn't figure out what went wrong. Your help is highly appreciated.

Thanks,
Frank

Below is the code:
-------------------------------------------------------------------------------------
var status = null;

var dlg = new Window('dialog', 'Window Phone Design Wizard', [100, 100, 470, 320]);
dlg.ScrTypePnl = dlg.add('panel', [15, 15, 355, 120], 'Screen type');

dlg.ScrTypePnl.radioBtn1 = dlg.ScrTypePnl.add('radiobutton', [15, 25, 150, 45], '3-line Pivot listview');
dlg.ScrTypePnl.radioBtn2 = dlg.ScrTypePnl.add('radiobutton', [15, 55, 150, 75], '2-line Pivot listview');
dlg.ScrTypePnl.radioBtn1.value = true;


//dlg.createBtn = dlg.add('button', [15, 180, 110, 205], 'Create', {name:'create'});
dlg.createBtn = dlg.add('button', [15, 180, 110, 205], 'Create');
dlg.cancelBtn = dlg.add('button', [130, 180, 235, 205], 'Cancel');

dlg.statusStr = dlg.add('statictext', [15, 150, 110, 180], status+' clicked');
//dlg.statusStr.hide();

dlg.show();

dlg.createBtn.onClick = function() {
var fileRef = new File('List_test.psd');
fileRef.open('r');
};
-------------------------------------------------------------------------------------
unpradise

OnClick function is not run?

Post by unpradise »

I found another document on ScriptUI and was able to get the function called correctly. The document is called "ScriptUI for dummies" and you can download it from here (http://www.kahrel.plus.com/indesign/scriptui.html). Thanks Peter for creating this tutorial!

The updated working code is pasted below for anyone else who has run into the same issue as I do.

--------------------------------------------------------------------------------
var status = null;

var win = new Window('dialog', 'Window Phone Design Wizard', [100, 100, 470, 320]);
win.ScrTypePnl = win.add('panel', [15, 15, 355, 120], 'Screen type');

win.ScrTypePnl.radioBtn1 = win.ScrTypePnl.add('radiobutton', [15, 25, 150, 45], '3-line Pivot listview');
win.ScrTypePnl.radioBtn2 = win.ScrTypePnl.add('radiobutton', [15, 55, 150, 75], '2-line Pivot listview');
win.ScrTypePnl.radioBtn1.value = true;


//win.createBtn = win.add('button', [15, 180, 110, 205], 'Create', {name:'create'});
var createBtn = win.add('button', [15, 180, 110, 205], 'Create');
var cancelBtn = win.add('button', [130, 180, 235, 205], 'Cancel');

var statusStr = win.add('statictext', [15, 150, 110, 180], status+' clicked');
//win.statusStr.hide();

createBtn.onClick = function() {
//var fileRef = new File('List_test.psd');
//fileRef.open('r');
alert('create');
};

win.show();
--------------------------------------------------------------------------------