Referring to the Master Controller Node


It is possible for the Master Controller node to refer to itself. The path to its own node is available in the global Controller object. Because this object is created by the Master Controller node, it is specific to that node.

function myCallback(newValue) { // Get the parent node of the Master Controller by using its path from the // Controller. var masterControllerParentNode = node.srcNode(myController.node, 0); }

The example above does not refer to the Controller object directly, but rather, to an object named myController. This is because the Controller object is only available at the root level of the script or within its own methods. To use the Controller object in other function in the script, it must be stored in a global variable:

// The script context will be initialized when Show Controls will be called. // Keep a script global copy of the Controller object. var myController = Controller; function point2dValueChanged(newPointValue) { // Not OK, the Controller global object isn’t available in callbacks var masterControllerParentNode = node.srcNode(Controller.node, 0); // OK, use a copy from the script global scope var masterControllerParentNode = node.srcNode(myController.node, 0); } // Called when the user shows the Master Controller module controls Controller.onShowControl = function() { Controller.controls = []; Controller.controls.push(new Point2dWidget); Controller.controls[0].valueChanged.connect(point2dValueChanged); }