Game Development Reference
In-Depth Information
between DisplayObject-generated events and all other events.
As we discussed earlier, events in ActionScript have three phases:
capture, target, and bubbling. Objects that dispatch events but
are not in the display list (which can include DisplayObjects that
have not been added to the stage) generate events only at the
target phase. In other words, other objects may listen for these
events only by attaching themselves directly to the dispatching
object.
DisplayObjects that are active somewhere in the display list are
capable of dispatching events that pass through all three phases.
When a DisplayObject that is on the Stage dispatches an event, it
actually originates at the Stage level and progresses through each
subsequent child to effectively
tunnel
down to the originating
object
this is the capture phase. The event then enters the target
phase and any listeners attached directly to the DisplayObject will
receive the event. Finally, if the event is set to bubble, it will
reverse its direction back up to the same display hierarchy it
traversed in the capture phase.
Frame Scripts
Before I go any further, I should go ahead and state for the record
that coding on the timeline should be avoided at all costs. There is
basically nothing that you can
tdowithclassestocontrolyour
DisplayObjects at this point, and forcing your code into classes
imposes better architecture and less sloppy shortcuts, which will
later come back to bite you.
Now, I say basically because until AS3 (Flash CS3, specifically),
you still had to put a stop() action on the last frame of any Movie-
Clip you didn
'
twanttoloop.Sinceswitchingtoall-classscripting
architecture, I found it very frustrating to not be able to easily
remove this last bit of straggling timeline code from my FLA once
and for all. Then, I discovered an undocumented method of Movie-
Clips. It
'
'
s called addFrameScript, and it
'
s a complete mystery to me
why Adobe hasn
t documented it or encouraged its use because it
is a fantastic piece of code. Basically, it allows you to tell a particu-
lar function to run when a certain frame of a MovieClip is hit.
Unlike all the other MovieClip functions, it is zero-based rather
than one-based, so you must subtract one from the desired frame
number to use it correctly. Here is its syntax in the context of a
MovieClip class.
'
public function MyMovieClip() {
addFrameScript(totalFrames-1, stop);
}
Now, when the clip reaches the last frame, it will call its stop()
method and not loop. Obviously, this has further-reaching implications
Search Nedrilad ::




Custom Search