Difference between revisions of "OnClick"

m (edited for clarity)
Line 2: Line 2:
 
''new to [[Analytica 4.6]]''
 
''new to [[Analytica 4.6]]''
  
The [[OnClick]] attribute is used with [[Buttons|Button]] and Picture objects and contains an [[Expression Syntax|expression]] that gets evaluated when the button is pressed.  
+
[[OnClick]] is an attribute of a [[Button|Button]] or Picture object. It contains an [[Expression Syntax|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.
  
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.
+
An [[OnClick]]expression 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 := operator, creating "side effect" that is not permitted in a normal variable definition.  
  
The expression syntax is the same as the syntax for a [[Definition]] attribute.  
+
The [[OnClick]] expression is always evaluated in [[Evaluation Modes|mid-mode]].
  
An [[OnClick]] expression has available to it two variables named <code>click_x</code> and <code>click_y</code>, 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, <code>click_x</code> and <code>click_y</code> are both [[Null]].
+
An [[OnClick]] expression has available to it two variables named <code>Click_x</code> and <code>Click_y</code>, 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 <code>Click_x</code> and <code>Click_y</code> are [[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.
+
Variables containing a[[Checkbox]] or [[Choice]] pulldowns, use the similar [[OnChange]] attribute, not [[OnClick]].
  
The [[OnClick]] expression is always evaluated in [[Evaluation Modes|mid-mode]].
+
== 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's[[Object 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.  
  
For [[Checkbox]]es and [[Choice]] pulldowns, use the [[OnChange]] attribute, not [[OnClick]].
+
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.  
  
== Inputs and Outputs ==
+
The Diagram does not normally display arrows to or from [[Button]]s and Pictures (as it does for most Variables), because they are switched off by default. [Is there a way to switch them on?]
  
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 [[Button]]s and Pictures are off by default.
+
== OnClick replaces the old Script attribute ==
  
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.
+
[[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.
 +
 
 
= See Also =
 
= See Also =
  
 
* [[Buttons]]
 
* [[Buttons]]
 
* [[OnChange]]
 
* [[OnChange]]

Revision as of 00:40, 3 July 2014

new to Analytica 4.6

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 := 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 aCheckbox 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 CheckboxorChoice 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. UseOnClick 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.

See Also

Comments


You are not allowed to post comments.