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
.
Содержание FLASH 8-LEARNING ACTIONSCRIPT 2.0 IN FLASH
Страница 1: ...Learning ActionScript 2 0 in Flash...
Страница 8: ...8 Contents...
Страница 18: ...18 Introduction...
Страница 30: ...30 What s New in Flash 8 ActionScript...
Страница 66: ...66 Writing and Editing ActionScript 2 0...
Страница 328: ...328 Interfaces...
Страница 350: ...350 Handling Events...
Страница 590: ...590 Creating Interaction with ActionScript...
Страница 710: ...710 Understanding Security...
Страница 730: ...730 Debugging Applications...
Страница 780: ...780 Deprecated Flash 4 operators...
Страница 830: ...830 Index...