
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
320
|
Chapter 13: MovieClip Subclasses
10. On the graphics layer, use Flash’s drawing tools to draw an idle face on frame 1,
a sad face on frame 10, and a happy face on frame 20.
You may have noticed that we added a stop( ) statement on frame 1 but not on
frames 10 and 20. We’ll see why in a moment. Now that the AvatarSymbol symbol is
complete, let’s turn our attention to the Avatar class.
The Avatar Class
The source code for the Avatar class is surprisingly simple. To subclass the
MovieClip class, we merely use the extends keyword, as we would for any other class.
The basic code is:
class Avatar extends MovieClip {
}
In ActionScript 1.0, MovieClip could be subclassed using an arcane
nest of
#initclip, Object.registerClass( ), and new MovieClip( ) calls.
In ActionScript 2.0, the Flash authoring tool handles all that dirty
work. Syntactically, MovieClip is extended like any other class, with
the
extends keyword.
The Avatar class defines two instance methods:
init( )
Initializes each Avatar instance
setState( )
Sets the avatar’s state using one of three constants (class properties)—
IDLE, SAD,
and
HAPPY.
Example 13-1 shows the Avatar class in its entirety.
Example 13-1. Avatar, a MovieClip subclass
class Avatar extends MovieClip {
public static var HAPPY:Number = 0;
public static var SAD:Number = 1; ...