Difference between revisions of "OnClick"

Line 1: Line 1:
 
[[Category:Attributes]]
 
[[Category:Attributes]]
 
''new to [[Analytica 4.6]]''
 
''new to [[Analytica 4.6]]''
 +
 +
__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 provides a way to let the user initiate actions beyond simply evaluating variables.   
 
[[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.   
Line 10: Line 12:
 
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 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]].
  
Variables containing a[[Checkbox]] or [[Choice]] pulldowns, use the similar [[OnChange]] attribute, not [[OnClick]].
+
Variables containing a [[Checkbox]] or [[Choice]] pulldowns, use the similar [[OnChange]] attribute, not [[OnClick]].
  
 
== Inputs and Outputs ==
 
== 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.  
+
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.  
  
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.  
+
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 [[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?]
 
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?]
Line 22: Line 24:
 
== 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]], meaning that we recommend that you don't use it. Use [[OnClick]] or [[OnChange]] instead.   
+
[[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.
 
[[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]]
 +
* [[Analytica Script]]

Revision as of 19:36, 12 January 2016

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 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.

See Also

Comments


You are not allowed to post comments.