Are you calling the function before the STLinks applet has finished loading? That will cause errors.
I have used this functions behind buttons and in code. But you need to make sure the applet is loaded and that you are logged in before calling them.
There is a function that gets called to indicate the applet is up, you can use that to change a switch so other functions can check to see if they can call stlinks functions.