OnClick

Revision as of 18:07, 2 April 2014 by Lchrisman (talk | contribs)

new to Analytica 4.6

The OnClick attribute is used with Button and Picture objects and contains an expression that gets evaluated when the button is pressed.

The expression can contain side-effects. For example, within the expression, you can assign to a global variable using the := operator. Such side-effects are not permitted in variable definitions. The result of the evaluation is not saved and is never used. Hence, the whole purpose of the expression is to enact some sort of side-effect.

The expression syntax is the same as the syntax for a Definition attribute.

An OnClick expression has available to it two variables named click_x and click_y, which contain the coordinates of the mouse within the button or image. 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 (in general, this may be different from the top-left corner of the node). If the button was "pressed" using the keyboard, or from typescript by typing the button's name, or by some other means not involving the mouse, click_x and click_y are both Null.

OnClick replaces the Script attribute for buttons which was used prior to Analytica 4.6. The Script attribute is still present and still works (so that legacy models still work), but has the disadvantage that is uses Typescript, which meant that you had to learn something new. Since OnClick uses expression syntax, you don't have to learn something new.

The OnClick expression is always evaluated in mid-mode.

For Checkboxes and Choice pulldowns, use the OnChange attribute, not OnClick.

Inputs and Outputs

When a Button's (or Picture's) OnClick attribute uses the value of a variable X, the variable X will appear in the Button's list of Inputs when viewing its Object Window, and the button will appear in X's list of Outputs. An input's popup menu will appear if you click just to the left of the button, and X will appear there as well. No arrow displays on the influence diagram, since arrows to/from Buttons and Pictures are off by default.

If the Button's (or Picture's) OnClick attribute assigns to a variable Y, then Y will appear as an output of the button, and the Button (or Picture) will appear as an input of Y. When you are viewing Y's Definition alone, this will appear surprising since the Button isn't in its Definition, but this is very helpful for pointing you to the places that can alter the value as a result of a side-effect. If you click to the right of the Button, a small outputs pop-up shows the variables assigned to by the OnClick expression.

See Also

Comments


You are not allowed to post comments.