Using Script Callbacks

Views gadgets are able to recognize specific mouse or keyboard events that apply to them and invoke the associated predefined Script callback functions.

To handle gadget events using callbacks, you must:

Writing a Callback

In Script for Views, callbacks have the following signature:

function CallBack(gadget, value)

Here is an example of a callback:

function OnButtonClick(button, value)

{

button.foreground = "red";

writeln("The additional value is: " + value);

}

The second argument passed to the callback is an optional value that you can specify when you set a callback in ivfstudio. The contents of the callback function can therefore be the following:

function OnGadgetClick(gadget)

{

gadget. foreground = "red";

}

Setting a Script Callback

There are two ways to set a callback to a gadget:

  • You can set callbacks in Views Studio, while designing panels. This is the easiest way.

  • You can set callbacks with the IlvGraphic::setCallback method. Using this method, you can set a callback to a gadget or modify it at run time. Here is an example:

myGadget.setCallback("Generic", "myCallback", "JvScript");

The first argument is the callback type that identifies the event to handle. The second argument is the callback function you defined. The third argument is always JvScript.