6.3  Using Scripts

6.3.1  Places

The two places where inline scripts occur are the <script> element and the action handlers of display elements.

6.3.2  The Dsp Namespace

There is a special namespace Dsp available in all scripts. This namespace contains the IDs of all display elements.

6.3.3  Action Handlers

Action handlers such as on-click provide a convenient reference self for addressing the display element of the action handler. Instead of self, you can also use the element's ID within the Dsp namespace, of course.

<image id="myimg" uri="gfx/button.png"
       on-click="self.uri = 'gfx/button-clicked.png'"/>
  

is equivalent to

<image id="myimg" uri="gfx/button.png"
       on-click="Dsp.myimg.uri = 'gfx/button-clicked.png'"/>
  

Some actions create an event object with information about the action. A click action, e.g. generates an event object with information about the mouse button that has been clicked.

The event object is a property of the display element, and can be accessed through the event property. Each event object has a set of properties itself, depending on the particular action. The event object of the click action, for instance, has a button property.

<image uri="gfx/button.png" on-click="print self.event.button"/>
  

See Common Tag Attributes and Handlers for a description of the event objects.

6.3.4  Arrays

Elements within an <array> tag can be addressed through a special array notation with index numbers:

<array length="5">
  <label id="mylabel" value="I'm a label"/>
</array>

<script>

  # change the value of the fourth element (index 3) in the array
  Dsp.mylabel[3].value = "I'm just a label"

</script>