OnClick



Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5


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_x and 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_x and Click_y are Null.

You can use the similar OnChange attribute, but not OnClick in any user input variable, such as one containing a Checkbox or Choice pulldowns.

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.

Alias nodes

New to Analytica 6.4

A click on an alias node runs its original node's OnClick expression. Within the expression, Self is an alias of the original object, whereas click_node_obj is an alias of the node that was actually clicked on. If you cilck on a non-alias node, then these are the same. To test for equality, use Handle(Self)=Handle(click_node_obj). Thus, if you care about which object is processing the OnClick, use Self, but if you care about which node was clicked, use click_node_obj.

You can set the OnClick attribute for the alias object itself. This is esoteric, and requires you to set the attribute from the Typescript Window or from your own code, since when you view the Object Window or Attribute pane for an alias, you are actually viewing the attributes of its original. When the alias object has its own OnClick expression, then it is run first, followed by the OnClick for the original. In this scenario, the alias's OnClick can suppress the subsequence processing of the original's OnClick by setting

click_continue := False

The click_continue's value can also be read, and this can be used in a non-alias's OnClick to detect the case in which an alias's OnClick ran just before this invocation. If an alias has not just run its own OnClick, the value of click_continue is False. If it has just run, the value is True.

History

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.

The Script attribute still exists to support legacy models. But, Script is now deprecated, meaning that we recommend that you don't use it. Use OnClick or OnChange instead.

See Also

Comments


You are not allowed to post comments.