Skip to end of metadata
Go to start of metadata

Syntax

sub init()
  ...

end sub

Synopsis

Allows initialization and other scripted control of a SceneGraph XML component.

Description 

If the <script> element contains the definition of a function named init() that has no parameters, that function will be invoked after the XML file has been parsed, and the nodes contained in the file have been created and had their fields set to the values in the XML. Typical uses of the init() function are to cache roSGNode values in the script global variable that will be frequently used in other functions in the script, and to set up field observers that will call other BrightScript functions when the observed field changes value. See Component Initialization Order for complete information on the initialization order for components defined in XML, and the implications of that initialization order for field settings and observer functions.

Example

If the XML file contains a Poster node element with id="MyPoster", the XML file below will be parsed, creating the Poster node, then the init() function will be called to cache a pointer to that node, set up an observer of the Poster node translation field, and print the value of the Poster node translation field in the console whenever it changes.

Using the init() Function in XML
  • No labels