I think I found the solution at this problem:
Error:
!ERROR!System:SCRIPT ERROR: Exception DefinitionNotFoundException in Function "queryAssociation" definition nor found _StateRootAssoc
Call Trace:
Script _StatesClassMethods lime 216 me(id=1000000799 class=_States)
Script _StatesClassMethods lime 317 me
The field "_StateRootAssoc" exists as an Association on the server
in "_StatesClassMethods"
areaRoot as NodeRef of Class AreaRoot = GetRootNode()
foreach a in QueryAssociation(areaRoot, "_StateRootAssoc", 0)
if a.target is kindof _StateRoot
StateRoot = a.target
break
.
.
areaRoot as NodeRef of Class AreaRoot return an Error in a client script not in server script
if we call $STATE by a client script, this may cause trouble.
EDIT:
Confirmation: Some _StateClassMethods functions are only available in server script, just like AreaRoot (a class server) in not found in database for client script
areaStates as NodeRef of Class _StateObjects = $STATES._GetStatesNodeByClass( "_areaStates")
Works fine in server script and don't works in client script.
Explication: the external function QueryAssociation exists on server AND client side but the field "_StateRootAssoc" exists only on server side. If you call $STATES._GetStatesNodeByClass (by example) in a client script, $STATES._GetStatesNodeByClass will call _GetStateRoot() who calls QueryAssociation(areaRoot, "_StateRootAssoc", 0) and as "_StateRootAssoc" don't exists on client side an error occurs.
We can use : "call server <a ScriptRef>:<a function>(<arguments>) [[optional failure clause]]" to call the server script executing the $State functions (function must be untrusted).