Using Screen References

RAMP-TS

Using Screen References

The script associated with a screen definition in RAMP-TS defines a JavaScript object. In effect, the screen script is the object that defines the screen and what it can do.

By now you should have encountered the concept of adding properties to the definitions of your screens. Typically these are defined at the start of the script like this example:

 

{

   /* Properties of screen Destination1 */

 

   sCurrentOrder     : "",

   fSkipIntroduction : false,

   fScrolling        : true,

 

The various functions in this screens definition would refernce them as this.sCurrentOrder, this.sSkipIntroduction and this.fScrolling.

They are useful for maintaining state within a screen definition and for communicating between different functions within the script.

By using the SCREEN("Screen Name") function you can obtain a reference to the named screens definition object.

For example, a junction Junction1 might have this code in its navigation script:

 

var oDest1 = SCREEN("Destination1");

    

oDest1.fSkipIntroduction = true;

oDest1.fScrolling = false;

 

This allows junction1 to directly access properties and even methods defined with destination screen Destination1.

This could have been coded:  

 

SCREEN("Destination1").fSkipIntroduction = true;

SCREEN("Destination1").fScrolling

 

But this is not the best solution for two reasons: 

  • SCREEN() will return a null reference if for some reason the definition of screen "Destination1" cannot be found, causing your script to fail.
  • The string "Destination1" needs to be converted to an object reference twice, so it is less efficient.  

 

The most proper form of this code is therefore:

var oDest1 = SCREEN("Destination1");

 

if (oDest1 != null)

{    

   oDest1.fSkipIntroduction = true;

   oDest1.fScrolling = false;