13.1. Testing StrategiesAll your audience ever sees is the finished product, not your intentions. So no matter how sophisticated your animation or how cleverly constructed your ActionScript code, if you don't test your animation and make sure it works the way you want it to, all your hard work will have been in vain. The following section shows you how to prepare for testing from the very beginning by following good Flash development policies. Also, you find out the differences between testing on the Stage and testing in Flash Player, along with tips for testing your animation in a Web browser. 13.1.1. Planning AheadThe more complex your animation, the more you need a thorough plan for testing it. Few of the guidelines in the next two sections are specific to testing in Flash. Instead, they're tried-and-true suggestions culled from all walks of programming life. Following them pays off in higher-quality animations and reduced time spent chasing bugs . Ideally, you should begin thinking about testing before you've created a single frame of your animation. Here are some preanimation strategies that pay off big: 13.1.1.1. Separate potentially troublesome elementsActionScript actions are very powerful, but they can also cause a lot of grief . Get into the habit of putting them into a separate layer named actions, either at the top of your list of layers or at the bottom, so that you'll always know where to find it. Putting all your sounds into a separate layer (named sounds) is a good idea, too. 13.1.1.2. Reuse as much as possibleInstead of cutting and pasting an image or a series of frames, create a graphic symbol and reuse it. That way, if a bug raises its ugly head, you'll have fewer places to go hunting. You can cut down on bugs by reusing ActionScript code, too. Instead of attaching four similar ActionScript actions to four different frames or buttons , create a single ActionScript function and call it four times. 13.1.1.3. Be generous with commentsBefore you know it, you'll forget which layers contain which images, why you added certain actions to certain objects, or even why you ordered your ActionScript statements the way you did. In addition to adding descriptive comments to all of the actions you create (there's an example at the end of this chapter, in Figure 13-19), get in the habit of adding an overall comment to the first frame of your animation. Make it as long as you want and be sure to mention your name , the date, and anything else pertinent you can think of. You create a comment in ActionScript two different ways, as shown below. // This is an example of a single-line ActionScript comment. /* This type of ActionScript comment can span more than one line. All you have to remember is to begin your multi-line comment with a slash-asterisk and end it with an asterisk-slash, as you see here. */ 13.1.1.4. Stick with consistent namesReferring to a background image in one animation as "bg," in another animation as "back_ground," and in still another as "Background" is just asking for trouble. Even if you don't have trouble remembering which is which, odds are your office teammates willand referring to an incorrectly spelled variable in ActionScript causes your animation to misbehave quietly . In other words, type Background instead of Background , and Flash doesn't pop up an error message; your animation just looks or acts odd for no apparent reason. Devise a naming convention you're comfortable with and stick with it. For example, you might decide always to use uppercase, lowercase, or mixed case. You might decide always to spell words out, or always to abbreviate them the same way. The particulars don't matter so much as your consistency in applying them. Note: Capitalization counts. Because Flash is case-sensitive, it treats background, Background, and BACKGROUND as three different names. 13.1.2. Techniques for Better TestingThe following strategies are crucial if you're creating complex animations as part of a development team. But they're also helpful if it's just you creating a short, simple animation by your lonesome.
|