ActionScript 3.0 introduced the Sprite class, which is a lightweight building block for interactive objects on stage. MovieClips are now derived from the new Sprite class. The factory method pattern can come in handy when developing applications that utilize sprites in Flash. Sprites are frequently added, and their behavior and appearance modified, during the course of Flash application development. Therefore, managing the dependencies between sprites and the rest of the application can be advantageous. We will create a simple example application called Shapes that manages sprite creation by introducing a factory method that enables clients to create sprites without explicitly specifying their class names.
The application shown in Figure 2-8 will
simply draw four different shapes based on the
Sprite class on the Flash stage. The first set of shapes will consist
of an unfilled rectangle and circle. The second set will be a
filled rectangle and circle. The example is not a
productive application, but it will serve as a springboard to the vertical
shooter game that we'll develop later in the chapter.
Figure 2-8. Screenshot of Shapes example stage
The Project window in Figure 2-9 shows the file structure of the Shapes example.
Figure 2-9. Shapes example Project window ...