OnClick is an Attribute of a Button or Picture object. It contains an expression that gets evaluated when you click the button or picture. It enables the user to perform actions beyond simply evaluating variables. In addition to allowing any kind of expression that you can use in a Definition attribute, it can also assign a value to a global variable using the := operator, creating "side effect" that is not permitted in a standard definition.
The OnClick expression is always evaluated in mid-mode.
The click location
An OnClick expression can do different things depending on where you click in the button or picture. It does this by using the two variables
Click_y. They contain the pixel coordinates of the mouse within the button or image. For a button, these coordinates are relative to its top-left corner. For a Picture node, they are relative to the top-left corner of the image (which may be different from the top-left corner of the node). If you "click" the button using the keyboard, or from Typescript by typing the button's name, or any method that doesn't involve a mouse (or trackpad), the values of
Click_y are Null.
Inputs and Outputs
Any variables or functions used in the OnClick attribute of a Button (or Picture) B appear in the the list of Inputs for B in its Object view or Attribute panel. Similarly, B appears in the Outputs of the variables or functions that it mentions. They also appear in the list of inputs (Outputs) when you press on on the left (right) edge of node B.
The Diagram does not normally display arrows to or from Buttons and Pictures (as it does for most Variables), because they are switched off by default.
OnClick was introduced in Analytica 4.6. It replaces the Script attribute used in older releases (prior to Analytica 4.6) for buttons, pictures, and input variables with Checkbox or Choice menus. OnClick and OnChange have several advantages over the now-deprecated Script attribute: Most important, they use the standard Analytica expression syntax, so you don't need to learn the slightly different Typescript syntax used in Script. And buttons using OnClick show up in the list of Inputs for any Variable that they assign to, so you can trace potential side effects on that Variable.