putObject
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 putObject function works in conjunction with the getObject 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 getObject function, see getObject on page 159.
Syntax
ogscript.putObject(Key, Value);
Parameters
Parameter |
Type |
Required |
Description |
Key |
String |
Yes |
The name of the object in which the data is being stored. |
Value |
String |
Yes |
The value to be stored. |
Returns
N/A.
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 anythingyou want with the data, now containedin the otherObject variable.
}