Page 1 of 1

Making buttons perform functions

Posted: September 20th, 2010, 3:29 pm
by maximumrfan
I have been making scripts for about 2 weeks, and I have created a script that simply makes a camera rig, and I decided to add a user interface to it so that it looks a little bit more professional. I have been wrestling JavaScript for 2 hours straight, and I can't get the button to do ANYTHING. I have looked at others scripts to see what they did (AE3D Exporter, SkyDome, ect.) and I am still stumped. I have my script up on my Opera Unite server if you want to download it and tell me what I'm doing wrong.
http://secretnetworkc2c.maximumrfan.ope ... e_sharing/
It will be "MRFCameraRig _ User Interface.jsx".
Thanks,
Matthew

Re: Making buttons perform functions

Posted: September 21st, 2010, 3:41 am
by Paul Tuersley
I couldn't access your script, but generally, after defining your UI you would include code like this to call a function when the button is clicked:

Code: Select all

pal.grp.mid.left.preset.deleteButton.onClick = onDeletePresetButton;
Don't put () after the function name or it'll get called when initially defined. Or if you want to create a new specific function for it you could use code like:

Code: Select all

pal.grp.top.progBarBut.buttons.about.onClick = function() {
	if (helpWindow instanceof Window) helpWindow.show();
	else helpWindow();
}
Check out the "Control event-handling callbacks" section of the Javascript Tools Guide pdf.

Re: Making buttons perform functions

Posted: September 21st, 2010, 1:14 pm
by maximumrfan
Paul Tuersley wrote:I couldn't access your script, but generally, after defining your UI you would include code like this to call a function when the button is clicked:

Code: Select all

pal.grp.mid.left.preset.deleteButton.onClick = onDeletePresetButton;
Don't put () after the function name or it'll get called when initially defined. Or if you want to create a new specific function for it you could use code like:

Code: Select all

pal.grp.top.progBarBut.buttons.about.onClick = function() {
	if (helpWindow instanceof Window) helpWindow.show();
	else helpWindow();
}
Check out the "Control event-handling callbacks" section of the Javascript Tools Guide pdf.
Thank you! I finally figured out what I was doing wrong. I uploaded the script I made to MegaUpload.
http://www.megaupload.com/?d=3SVNF4F4
P.S. It's in alpha/beta/whatever-you-call-it phase.
Thanks,
Matthew