So here's an example where, if you were trying to stop multiple help windows from being created, that's no longer a problem as this will only create one if necessary.
But just for the hell of it, I also stuck in an example that turns the help button on the main panel on/off. Don't really know what you're trying to do here but hopefully this will give you all the info you need.
function myAwesomeScript(thisObj) {
var helpWindow; // define in main script scope so it's accessible throughout
function buildUI(thisObj) {
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", undefined, undefined, {resizeable: false});
//myPanel.text = "Expression Controller";
pal.orientation = "row";
pal.alignChildren = ["left", "top"];
pal.spacing = 10;
pal.margins = 10;
pal.help = pal.add("button", undefined, undefined);
pal.help.helpTip = "Help";
pal.help.text = "?";
pal.help.preferredSize.width = 27;
pal.help.preferredSize.height = 27;
pal.help.alignment = ["left", "center"];
pal.help.onClick = function () {
if (helpWindow == null || helpWindow.visible == false) buildHelp(); // only create helpWindow if it isn't already visible
else helpWindow.show();
};
return pal // return panel object
}
function buildHelp() {
helpWindow = new Window("palette","Help - About",undefined,{resizeable:false});
helpWindow.orientation = "column";
helpWindow.alignChildren = ["center","top"];
helpWindow.spacing = 12;
helpWindow.margins = 15;
var test = helpWindow.add("button", undefined, "Try Me!");
test.onClick = function() {
if (myPanel.help.enabled == true) myPanel.help.enabled = false; // here's an example of now being able to access the UI from outside the scope of the buildUI function
else myPanel.help.enabled = true;
}
helpWindow.onClose = function() {
myPanel.help.enabled = true; // just in case you left it turned off
}
helpWindow.show();
}
var myPanel = buildUI(thisObj); // receive panel object. define in main script scope so it's accessible throughout
if (myPanel != null) {
if (myPanel instanceof Window) {
myPanel.center();
myPanel.show();
}
}
}
myAwesomeScript(this);