I've created a global method that captures the current form and element, then looks to a table called 'agent_script' for agent positioning, baloon size and location.
The idea here, is to set this as the onFocusGained method (or first step of another onFocusGained method) of the elements on a form. With the agent active, as the user goes from element to element, the bird gives context-specific help.
I initially was creating a method for each field, so this will save me some time, but also I plan to open this up to the user interface, and allow the client administrator to edit the help text.
Thought I'd share this here, in case it might save someone else a bit of work. Of course, I'm also open to input and/or improvements!
//
// This method will check for agent messages for the current form and element. If none,
// the agent's location and balloon size will be reset.
//
globals.formCurrent = currentcontroller.getName(); //capture the form name
if ( application.getMethodTriggerElementName() ) //if specified trigger element, set; else 'unknown'
{
globals.elementCurrent = application.getMethodTriggerElementName();
}
else
{
globals.elementCurrent = 'unknown';
}
// if specified, set the balloon size for the agent, otherwise set to default.
if ( forms[currentcontroller.getName()].global_current_agent_script.size_x && forms[currentcontroller.getName()].global_current_agent_script.size_y )
{
plugins.agent.setBalloonSize(forms[currentcontroller.getName()].global_current_agent_script.size_x, forms[currentcontroller.getName()].global_current_agent_script.size_y );
}
else
{
plugins.agent.setBalloonSize(200,100);
}
// if specified, set location of agent, otherwise set to either upper left of element, or in lower right-hand corner.
if ( forms[currentcontroller.getName()].global_current_agent_script.loc_x && forms[currentcontroller.getName()].global_current_agent_script.loc_y )
{
plugins.agent.setLocation(forms[currentcontroller.getName()].global_current_agent_script.loc_x, forms[currentcontroller.getName()].global_current_agent_script.loc_y );
}
else
{
//if specific element and msg, use position, else, lower right
if (application.getMethodTriggerElementName() && forms[currentcontroller.getName()].global_current_agent_script.msg_text)
{
var locx = forms [currentcontroller.getName()].elements[application.getMethodTriggerElementName()].getLocationX();
var locy = forms [currentcontroller.getName()].elements[application.getMethodTriggerElementName()].getLocationY();
var elewidth = forms [currentcontroller.getName()].elements[application.getMethodTriggerElementName()].getWidth();
plugins.agent.setLocation(locx + elewidth + 50 , locy );
}
else
{
plugins.agent.setLocation(application.getWindowWidth()- 200, application.getWindowHeight()- 200);
} }
// If there's a message, speak it.
if ( forms[currentcontroller.getName()].global_current_agent_script.msg_text )
{
plugins.agent.speak(forms[currentcontroller.getName()].global_current_agent_script.msg_text);
}