OnClick



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 provides a way to let the user initiate actions beyond simply evaluating variables.

An OnClickexpression can contain anything you can put in a Definition attribute, using the same syntax. But, it can also assign a value to a global variable using the := operator, creating "side effect" that is not permitted in a normal variable definition.

The OnClick expression is always evaluated in mid-mode.

An OnClick expression has available to it two variables named Click_x and Click_y, which contain the pixel coordinates of the mouse within the button or image. This means, for example, that the OnClick expression can do different things depending on which part of an image you click. For a button, these coordinates are relative to the top-left corner of the button. 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 means not using the mouse, the values of Click_x and Click_y are Null.

Variables containing a Checkbox or Choice pulldowns, use the similar OnChange attribute, not OnClick.

Inputs and Outputs

When the OnClick attribute of a Button (or Picture), B, mentions a variable X, X will appear in the the list of Inputs when you view B'sObject Window. Similarly, the button B will appear in X's list of Outputs. If you press just to the left of the button node, it shows a popup menu listing X as an Input.

Similarly, if OnClick assigns to a global Variable Y, Y will appear in Button B's list of Outputs; Button B will appear in Y's list of Inputs; and, when you press to the right of Button B, it shows a popup menu listing Y as an Output.

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. [Is there a way to switch them on?]

OnClick replaces the old Script attribute

OnClick replaces the Script attribute used in older releases (prior to Analytica 4.6) for buttons, pictures, and input variables with Checkbox or Choice menus. The Script attribute is still present, so that legacy models still work. But, Script is now deprecated, meaning that we recommend that you don't use it. Use OnClick or OnChange instead.

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.

History

OnClick was introduced in Analytica 4.6.

See Also

Comments


You are not allowed to post comments.