/
Accessing objects in lists

Information Classification: External Restricted.
See https://www.chili-publish.com/security

Accessing objects in lists

List Objects

Various objects in the document's object model inherit from Document Object Model - DocumentListBase. Examples are "document.colors", "document.variables", "document.pages", "document.pages[0].frames", etc.

Object Descriptors for lists

To gain access to items within lists, you can use a "[]" annotation to provide one of the following descriptors to get an item (which will be evaluated in this order):

  • ID
  • Index
  • Name
  • Tag
function GetInfo()
{
   //GET A VARIABLE VALUE
   var myVariable = editor.GetObject("document.variables[MY_VARIABLE_NAME]");
   alert(myVariable.name);
   //SET A VARIABLE VALUE, USING AN ID
   editor.SetProperty("document.variables[" + myVariable.id + "]","value","NEW VALUE");

   //GET THE FIRST FRAME ON THE FIRST PAGE
   var myFrame = editor.GetObject("document.pages[0].frames[0]");
}

Looping through a list

You can use the "length" property of a list to get its amount of items, and use that to build an object descriptor within a loop:

function ListVariables()
{
   //GET A VARIABLE VALUE
   var numVariables = editor.GetObject("document.variables").length;
   var names = "";
   for (var a=0;a<numVariables;a++)
   {
      var myVariable = editor.GetObject("document.variables[" + a + "]");
      names += myVariable.name + "\n";
   }
   alert(names);
}

Accessing Frames

Frames are part of a page, and typically are accessed either through the selected frame (see Accessing selected frames and other resources). For example:

function GetFirstFrame()
{
   var myFrame = editor.GetObject("document.pages[0].frames[0]");
   return myFrame;
}

There is however also a helper-property, "allFrames", on the document level, which can be used to find frames throughout the document, for example based on a tag or ID:

function GetFrameByDescriptor(desc)
{
   var myFrame = editor.GetObject("document.allFrames[" + desc + "]");
   return myFrame;
}

Selecting a frame in the editor

It is possible to trigger the selection of a frame via Javascript.
Most of the times, this will be done with a tagged frame, but the selection of a specific frame can be done as described above, underneath "Object descriptors for lists"

The sample below will select a frame that has been tagged as 'BG_IMAGE'.

function selectFrameWithTag(){
    var frametag = "BG_IMAGE";
	editor.ExecuteFunction('document.allFrames[' + frametag + ']', 'Select');
}

Related content

Accessing selected frames and other resources
Accessing selected frames and other resources
More like this
JavaScript Navigation
JavaScript Navigation
More like this
Document Object Model
Document Object Model
Read with this
DocumentListBase
More like this
Finding object properties and functions
Finding object properties and functions
Read with this
Document Object Model - DocumentListBase
Document Object Model - DocumentListBase
More like this

All information on this page must be treated as External Restricted, or more strict. https://www.chili-publish.com/security