EasyManua.ls Logo

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH - Page 349

MACROMEDIA FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
830 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Using the Delegate class 349
The remaining three sections of code each create a new Button component instance on
the Stage, reposition the instance, and add an event listener for the
click event. The first
button adds an event listener for the
click event and passes a reference to a click
handler function directly. The second button adds an event listener for the
click event
and passes a reference to a listener object, which contains a handler for the
click event.
Finally, the third function adds an event listener for the
click event, uses the Delegate
class to dispatch the click event in the
this scope (where this equals _level0) and passes
a reference to the
click handler function.
4. Select Control > Test Movie to test the Flash document.
5. Click each button instance on the Stage to see which scope in which the event is handled.
a. Click the first button on the Stage to trace the following text in the Output panel:
[click] event on _level0.one_button instance.
this -> _level0.one_button
When you click one_button instance, the this scope refers to the button instance
itself.
b. Click the second button on the Stage to trace the following text in the Output panel:
[click] event on _level0.two_button instance.
this -> [object Object]
When you click the two_button instance, the this scope refers to the
buttonListener object.
c. Click the third button on the Stage to trace the following text in the Output panel:
[click] event on _level0.three_button instance.
this -> _level0
When you click the three_button instance, the this scope refers to the scope that
you specify in the
Delegate.create() method call, or in this case, _level0.

Table of Contents

Related product manuals