Dynamically Changing States | 307
- Repeat Steps 1 through 5 to create a movie clip namedAlien. Make a different
ship and point it in the opposite direction as theEarthlingmovie clip spaceship.
Once you’re finished, you should see both the Alien and Earthling movie clips in
the Library panel.
Building the weapons
Originally, we tried building the spaceship and weapon as a single movie clip, but
after experimentation, it made more sense to make separate movie clips for better
flexibility. The ones provided here are extremely simple, but you can add any kind of
enhancement you want—blast trails, sound, and step-down to fire. The following
steps show simple ones for seeing how the Observer design pattern state change can
be triggered.
- Select Insert ➝ New Symbol from the menu bar. Name the movie clipbullet,
using all lowercase for the name. Select Movie clip as the Behavior, and click
OK. You are now in the Symbol editing mode. - Draw something that you want to look like the projectile shooting at the Alien.
We used a simple oval with a fin on the top for a shark-like missile with the
dimensions, W=23, H=7.3. The height includes the fin; so it’s a pretty small mis-
sile, but proportionate to the Earthling ship. When you’re done, click Scene 1 to
exit the Symbol editing mode. - Select Insert ➝ New Symbol from the menu bar When the New Symbol win-
dow opens, type inMissilein 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. - Click on 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 seeMissileappear andflash.display.MovieClipin the
Base class window. Click OK.
Figure 8-3. Earthling spaceship