In the
Global JavaScript part of the Scripting tab in the
Properties Dialog you may define
functions (not variables) which will be available from the other scripts. You can also define
function ggbOnInit(name, api), which is called automatically once the construction is loaded. The
ggbOnInit function can be used for registering some
listeners, as shown below.
Example:
function onAdd(name){
alert("Object "+name+" was added.");
}
function ggbOnInit(name, api){
api.registerAddListener("onAdd");
}
First we defined function
onAdd that given a string shows a message depending on that string. After that, using the
ggbOnInit function, we told
GeoGebra to call this function whenever a new object is added. Once we reload our construction, function
ggbOnInit will be called and since then, when user adds a point named e.g.
, message "Object A was added" will appear.
You can also use
listeners for actions like rename, delete and clear construction. A complete list is available in
Reference:JavaScript.
Note: Using any ggbApplet methods in
Global JavaScript outside of ggbOnInit will not work as intended since they will be called before the construction is loaded.