Using component event handlers

The easiest way to handle a component event is to use the on() component event handler. You can assign the on() handler to a component instance, just as you would assign a handler to a button or movie clip.

The keyword this, used inside an on() handler attached to a component, refers to the component instance. For example, the following code, attached to the Button component instance myButtonComponent, sends "_level0.myButtonComponent" to the Output panel:

on(click){
  trace(this);
}

To use the on() handler:

  1. Drag a CheckBox component to the Stage from the Components panel.
  2. Select the component and select Window > Actions.
  3. In the Actions panel, enter the following code:
    on(click){
      trace("CheckBox was clicked");
    }
    

    You can enter any code you wish between the curly braces({}).

  4. Select Control > Test Movie and click the check box to see the trace in the Output panel.

    For more information, see each event entry in Components Dictionary.