User Guide

onUpdate 665
onUpdate
Availability
Flash Player 6.
Usage
function onUpdate() {
...statements...;
}
Parameters
None.
Returns
Nothing.
Description
Event handler; onUpdate is defined for a Live Preview used with a component. When an instance
of a component on the Stage has a Live Preview, the authoring tool invokes the Live Previews
onUpdate function whenever the component parameters of the component instance change. The
onUpdate function is invoked by the authoring tool with no parameters, and its return value is
ignored. The
onUpdate function should be declared on the main Timeline of the Live Preview.
Defining an
onUpdate function in a Live Preview is optional.
For more information on Live Preview, see Using Components.
Example
The onUpdate function gives the Live Preview an opportunity to update its visual appearance to
match the new values of the component parameters. When the user changes a parameter value in
the components Property inspector or Parameters tab in the Components inspector,
onUpdate is
invoked. The
onUpdate function does something to update itself. For instance, if the component
includes a
color parameter, the onUpdate function might alter the color of a movie clip inside
the Live Preview to reflect the new parameter value. In addition, it might store the new color in
an internal variable.
The following example uses the
onUpdate function to pass parameter values through an empty
movie clip in the Live Preview. To see this code work, place a labeled button component on the
Stage with a variable labelColor that specifies the color of the text label. The following code is in
the first frame of the main Timeline of the component:
/* Define the textColor parameter variable to specify the color of the button
label text.*/
buttonLabel.textColor = labelColor;
In the Live Preview, place an empty movie clip named xch in the Live Preview. Then place the
following code in the first frame of the Live Preview. Add
"xch" to the labelColor variable path
to pass the variable through the
my_mc movie clip:
//Write an onUpdate function, adding "my_mc." to the parameter variable names:
function onUpdate (){
buttonLabel.textColor = my_mc.labelColor;
}
CHAPTER 7
ActionScript for Flash