Using Listeners To Handle Events - MACROMEDIA FLASH MX 2004-USING COMPONENTS Use Manual

Using components
Hide thumbs Also See for FLASH MX 2004-USING COMPONENTS:
Table of Contents

Advertisement

The keyword
this
component instance. For example, the following code, attached to the Button component
instance
myButton
on(click){
trace(this);
}
To use the on() event handler:
Open the file TipCalculator1.fla from Macromedia\Flash MX
1.
2004\Samples\HelpExamples\TipCalculator.
On the Stage, select the TextInput component beside the "Enter subtotal" text.
2.
Open the Actions panel, if it isn't already open.
3.
Look at the following code assigned to the subtotal_ti TextInput component:
4.
on(change){
this._parent.calculate();
}
This code calls the
when the TextInput component changes. The
according to which radio button is selected.
Select each of the radio buttons to see their event handlers.
5.
Each radio button also calls the
Select Control > Test Movie to use the tip calculator.
6.

Using listeners to handle events

The version 2 component architecture has a broadcaster/listener event model. (A broadcaster is
sometimes also referred to as a dispatcher.) It is important to understand the following key points
about the model:
All events are broadcast by an instance of a component class. (The component instance is the
broadcaster.)
A listener can be a function or an object. If the listener is an object, it must have a callback
function defined on it. The listener handles the event; this means the function, or callback
function, executes when the event occurs.
56
Chapter 4: Handling Component Events
, used inside an
on()
, sends "_level0.myButton" to the Output panel:
function that is defined on Frame 1 of the main Timeline
calculate()
calculate()
handler attached to a component, refers to the
calculate()
function when clicked.
function calculates the tip

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?

Subscribe to Our Youtube Channel

This manual is also suitable for:

Flash mx

Table of Contents