ActionScript 3.0 Design Patterns

(Chris Devlin) #1

306 | Chapter 8: Observer Pattern


Launching the Space Battle


In Example 8-19, you’ll find a class that handles a battle in space. However, even


before beginning on theChangleHandlerclass, you first need to build some movie


clips, and to do so, we need to start with a Flash document file. The following steps


are just the first to set up the stage.


Setting up the Flash document



  1. Open a new Flash document.

  2. Set the stage size to 650× 450, and set the background to gray.

  3. Add a star field of your own design using yellow stars and shooting stars. Don’t
    put in too many—just enough to give it an outer-space look and feel.

  4. In the Document class window in the Properties inspector, type in
    ChangeHandler.

  5. Save the file asAliensAttack.flain the same folder with the other files for this
    application.


Building the spaceships


Once you have your Flash document set up, you need to build the spaceship movie


clips.



  1. Select Insert➝ New Symbol from the menu bar.


When you name a movie clip that you’ll use as a class, be sure to fol-
low the same naming conventions as you would for any class. The first
character should be capitalized and contain no spaces. So be sure to
useEarthlingrather thanearthling, and don’t put any spaces or other
unacceptable characters in the name.


  1. When the New Symbol window opens, type inEarthlingin the Name window,
    and select Movie clip as the Behavior. If you see a button named Advanced, click
    it. It opens up part of the New Symbol window that you need for the next step.

  2. Click the Export for ActionScript checkbox in the Linkage group. You should
    see the Export in first frame checkbox automatically selected. Also, in the Class
    window, you should seeEarthlingappear andflash.display.MovieClipin the
    Base class window. Click OK.

  3. You are now in the Symbol edit mode. The center of the movie clip is indicated
    by the crosshair in the middle of the stage.

  4. Using the drawing tools, draw a simple spaceship with the dimensions W=83,
    H=47. Figure 8-3 shows an example enlarged 400 percent. Click the Scene icon,
    located at the top left above the stage, when you’re finished, and you should see
    your movie clip in the Library.

Free download pdf