Difference between revisions of "OnClick"

m
Line 3: Line 3:
 
__TOC__
 
__TOC__
  
 +
[[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 enables the user to perform actions beyond simply evaluating variables.  In addition to allowing any kind of [[Expression Syntax|expression]]  that you can use in a [[Definition]] attribute, it can also assign a value to a global variable using the [[Assignment Operator :=|:= operator]], creating "side effect" that is not permitted in a standard definition.
  
[[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 [[OnClick]] expression is always evaluated in [[Evaluation Modes|mid-mode]].
 
 
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 the [[Assignment Operator :=|:= operator]], creating "side effect" that is not permitted in a normal variable definition.  
 
  
The [[OnClick]] expression is always evaluated in [[Evaluation Modes|mid-mode]].
+
== The click location ==
  
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]].
+
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 <code>Click_x</code> and <code>Click_y</code>. 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 <code>Click_x</code> and <code>Click_y</code> are [[Null]].
  
Variables containing a [[Checkbox]] or [[Choice]] pulldowns, use the similar [[OnChange]] attribute, not [[OnClick]].
+
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 ==
 
== Inputs and Outputs ==
Line 24: Line 23:
 
== OnClick replaces the old Script attribute ==
 
== 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 features|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==
 
==History==
[[OnClick]] was introduced in [[Analytica 4.6]].
+
[[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 features|deprecated]], meaning that we recommend that you don't use it. Use [[OnClick]] or [[OnChange]] instead. 
  
 
== See Also ==
 
== See Also ==

Revision as of 02:14, 4 March 2020


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

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

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.