338
Handling Events
You can attach
onClipEvent()
and
on()
only to movie clip instances that have been placed
on the Stage during authoring. You cannot attach
onClipEvent()
or
on()
to movie clip
instances that are created at runtime (using the
attachMovie()
method, for example). To
attach event handlers to objects created at runtime, use event handler methods or event
listeners. (See
“Using event handler methods” on page 330
and
“Using event listeners”
on page 332
.)
For more information on button and movie clip event handlers, see the following topics:
■
“Using on and onClipEvent with event handler methods” on page 338
■
“Specifying events for on or onClipEvent methods” on page 340
■
“Attaching or assigning multiple handlers to one object” on page 341
Using on and onClipEvent with event handler
methods
You can, in some cases, use different techniques to handle events without conflict. Using the
on()
and
onClipEvent()
methods doesn’t conflict with using event handler methods that
you define.
For example, suppose you have a button in a SWF file; the button can have an
on(press)
handler that tells the SWF file to play, and the same button can have an
onPress()
method,
for which you define a function that tells an object on the Stage to rotate. When you click the
button, the SWF file plays and the object rotates. Depending on when and what kinds of
events you want to invoke, you can use the
on()
and
onClipEvent() methods
, event
handler methods, or both techniques of event handling.
However, the scope of variables and objects in
on()
and
onClipEvent()
handlers is different
than in event handler and event listeners. See
“Event handler scope” on page 343
.
You can also use
on()
with movie clips to create movie clips that receive button events. For
more information, see
“Creating movie clips with button states” on page 342
. For
information on specifying events for
on()
and
onClipEvent()
, see
“Specifying events for on
or onClipEvent methods” on page 340
.
NO
TE
Attaching
onClipEvent()
and
on()
handlers is not a recommended practice. Instead, you
should put your code in frame scripts or in a class file, as demonstrated throughout this
manual. For more information, see
“Using event handler methods” on page 330
and
“Attaching code to objects” on page 746
.
Содержание 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...