Adobe 12040118 - After Effects Standard Using Manual page 205

Using help
Hide thumbs Also See for 12040118 - After Effects Standard:
Table of Contents

Advertisement

Adobe After Effects Help
Using Help
Each class of UI element has a set of callback methods defined for it. For windows, there are callbacks like
onClose(), onMove(), and onResize(). For controls, callbacks vary from type to type. A typical callback is
onClick() for button, radiobutton, and checkbox elements, and onChange() for edittext fields, scrollbars, and
sliders.
To handle a given event for some UI element, simply define a property of the same name as the event callback
in the element and assign a JavaScript function you have defined to it. The example below uses "in line"
functions, which employ a unique syntax and do not require a name. However, you can also define the
function elsewhere in the script. In that case, simply assign the name of the function to the event handler
property. The scripting user interface calls these functions on event notifications if defined.
Examples:
/*' has buttons' checkbox enables or disables the panel that
deter mines the justification of the 'aler t' button g roup */
dlg .hasBt nsCb.onClick =
function () { this.parent.aler tBt nsPnl.enabled = this.value; };
//The Build and Cancel buttons close this dialog
w i t h ( d l g . b t n Pn l ) {
buildBt n.onClick =
fu n ctio n () { th is.pa ren t. pa re n t. close (1); };
cancelBt n.onClick =
fu n ctio n () { th is.pa ren t. pa re n t. close (2); };
} ;
Because event callback functions work as methods of the object in which they are defined, the functions have
access to the object via the "this" JavaScript keyword. In the examples above, "this" refers to the UI object a
given callback is defined in, so properties of the UI object can be accessed relative to the "this". For example,
because each UI object has a parent property which is a reference to its container object, this.parent gets you a
reference to the object's parent object.
To elaborate further on this point, a button( ) is contained within a panel, which is contained within a window,
all of which are ultimately closed. The progression is from smaller to larger UI moving from left to right.
buildBtn.onClick = function () {this.parent.parent.close(1);};
Also be aware that you can simulate user actions by sending an event notification directly to a UI element, via
the element's notify() method. In this manner, a script can generate events in the controls of a window, as if a
user was clicking buttons, entering text, moving a window, etc.
radiobutton and checkbox elements have a boolean value property; using notify() to simulate a click on these
elements also changes the value of this property, just like clicking the element would do. For instance, if the
value of a checkbox 'hasBtnsCb' in our example above is true, the following example changes the value to false:
if (d lg .ha sBt n sC b.v a lu e == t r u e)
d l g . h a s B t n s C b. n o t i f y ( ) ;
// dl g .ha sB t n sCb.v a lu e is n ow fa lse
For a complete description of the different event callback methods and notify(), see "Common methods and
event handlers" on page 217.
Using Help
button
panel
dialog
Creating User Interface Elements
Back
Back
205
205

Advertisement

Table of Contents
loading

This manual is also suitable for:

After effects

Table of Contents