[Tip] Method as a function and as a method
by David Workman
Data Mosaic
Save some effort and have methods do double duty as both directly called methods or methods called by other methods. Just put a check in at the beginning of the code to see if the method was called by a UI object (you need to give the object a name) or if there is an argument being passed to the method (in which case you need to be passing an argument!).
Here's the basic idea by checking to see if a named object event is responsible for triggering the code:
if (application.getMethodTriggerElementName()) {
//method called from UI event
var input = application.getMethodTriggerElementName()
}
else {
//method called from another method so grab the arguments
var input = arguments[0]
}
Another example checking for a passed argument instead:
//set the tab panel name for this method
var tabPanelName = 'tabs_details';
//check to see if called from another method
if (!arguments[0])
{
var btn_name = application.getMethodTriggerElementName();
}
else
{
var btn_name = arguments[0];
}
//get number of tabs
var tab_num = elements[tabPanelName].getMaxTabIndex();
//activate correct tab and flip tab buttons
for ( var i = 1 ; i <= tab_num ; i++ )
{
var tab_name = 'tab_' + i;
if (btn_name == tab_name)
{
//elements[tab_name].fgcolor = '#FAAF0A';
elements[tab_name].bgcolor = '#ffffff'
elements[tab_name].setFont('Verdana,1,10');
//set tab index
elements[tabPanelName].tabIndex = i;
}
else
{
//elements[tab_name].fgcolor = '#000000';
elements[tab_name].bgcolor = '#999999'
elements[tab_name].setFont('Verdana,0,10');
}
}
Comments (4)