Traverse Object Hierarchy

The Object Hierarchy script is used as an example of string replacement.

You can copy the code from this page and paste it into the SOASTA CloudTest > Script Editor, or use the following links to download and import the XML for the entire Object Hierarchy Composition or just the Object Hierarchy Script.

Note:  Use the following links to download and import the XML for the entire Object Hierarchy Composition or just the Object Hierarchy Script or copy and paste the script code from here.
var tree = "";

//Get the composition object tree and post it to the result object as LEVEL_INFO
displayItem($context.composition, "");
$context.result.postMessage($context.result.LEVEL_INFO, "Composition object tree", tree);

function displayItem(item, indent)
{
  if (item == null)
   {
    tree += indent + "(null)";
   }
    else
    {
     tree += indent + "Item: \"" + item.name + "\", type: " + item.type + "\n";

     tree += indent + "Children:\n";

      var children = item.children;
      if (children == null)
      {
        tree += indent + " (none)\n";
     }
     else
      {
       for (var i = 0; i < children.length; i++)
        {
          displayItem(children[i], indent + " ");
        }
      }
    }
}