getObject

You can create an object and reference it in other parts of the code. Some possible uses include:

·         Storing parsedXML data in an objectso you don’t have to re-parseit.

·         Storing the results of an asyncHTTP post so you don’t have to re-fetchit.

·         Storing connection code so you cna reference it wherever your code needs to establishthat connection.

The getObject function works in conjunction with the putObject function. The putObject function defines the object. The getObject function references the object. The scope of a defined object is global, so you can reference it from anywhere in your panel code.

For information about the putObject function, see putObject on page 170.

Syntax

ogscript.getObject(Key);

Parameters

Parameter

Type

Required

Description

Key

String

Yes

The name used to reference what is being stored.

Returns

String.


 

Example

The following example parses and stores data from an XML file in a variable so it can be used globally without the need to re-parse the XML data each time you want to use it.

It defines a function named loadTheXML, which uses the parseXML function to retrieve XML data from a file and load it into a variable named myObject. It then uses the putObject function to copy the data into a variable named myXML. The readTheXML function loads the data into a variable named otherObject.

function loadTheXML()

{

var myObject= ogscript.parseXML('file:/c:/mydocument.xml'); ogscript.putObject('myXML',myObject);

}

 

function readTheXML()

{

var otherObject = ogscript.getObject('myXML');

// Do anything you want with the data, now containedin the otherObject variable.

}