Flash CS4 Professional in 24 Hours- P15

Chia sẻ: Cong Thanh | Ngày: | Loại File: PDF | Số trang:30

0
35
lượt xem
7
download

Flash CS4 Professional in 24 Hours- P15

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Flash CS4 Professional in 24 Hours- P15: The creation of this book could not have happened without the skill and patience of many, many people at Sams Publishing. Most of all, I want to thank Mark Taber for offering me this opportunity and Philip Kerman for writing such a great book. I also greatly appreciate the efforts of Songlin Qiu for keeping me on track and organized, not an easy task.

Chủ đề:
Lưu

Nội dung Text: Flash CS4 Professional in 24 Hours- P15

  1. File Size Considerations 411 graphics don’t matter, but sounds and bitmaps are more significant. Any- thing you can do to reduce their size results in major savings in the file size of a movie. Sounds Flash provides several ways to compress audio and bitmaps. You saw that these compression settings are specified individually via the Library item properties for each imported bitmap or sound in Hour 3, “Importing Graphics into Flash,” and Hour 13, “Including Sound in Animations.” You also see in Hour 24, “Publishing a Creation,” how you can set compression settings for all imported bitmaps and sounds at once via the Publish Set- tings dialog box. Although you know where to set the compression set- tings, you might not fully understand how this affects your movies. Different types of compression exist. For audio, you should always use MP3 or Voice. Although Flash supports Adaptive Differential Pulse Code Modulation, or ADPCM, you should only use this if you are publishing your movie as Flash 3 or lower—that is, you want the audio in your movie to work for people who have only the Flash 3 player. If you happen to be delivering your movie to run only on your hard drive, you can specify no compression and use Raw. Barring those two situations, MP3 is the best choice. A simple relationship exists between quality and file size. You learned how to set the compression settings individually for just one sound in Hour 1, “Basics.” Basically, you try one setting and listen to how it sounds. As you try greater levels of compression, you both hear the difference and see the file size change. It’s just a matter of balancing these two priorities—good quality and small file size. There are a couple additional ways to optimize sounds. The easiest one to remember is that stereo sounds are twice as big as mono sounds. There- fore, you should enable Flash to always convert stereo to mono, unless you truly need stereo. Keep in mind you can still use stereo panning effects on sounds that are mono. When a frame with sound is selected, you can use the Effect feature, you can use preset effects (such as Fade Right to Left), or you can make your own effects to give a mono sound stereo-like effects (see Figure 22.4).
  2. 412 HOUR 22: Minimizing File Size FIGURE 22.4 The Edit Envelope dialog box (ac- cessed from the Properties panel) enables you to create panning ef- fects using mono sounds. Another great way to reduce the impact of sounds on file size is to trim ex- cessive silence from the beginning and end of every sound. It’s customary for audio engineers to pad every sound file with a little silence. Sounds take up the same file space for every second they’re played, regardless of whether they’re audible (although compression tends to compensate for this). Ideally, sounds should be trimmed before they are imported, but you can trim them inside Flash through the Edit Envelope dialog box. You can review this technique in Hour 12, “Reusing Your Animations with Motion Presets.”. By trimming excessive silence in a particular sound, we cut the sound by 10 percent in a recent project. That might not seem like a lot, but because sounds can be very large, 10 percent of a large file can be signifi- cant. What’s more, because we just trimmed out the silence, we didn’t lose anything. Consider, too, that a long fading-out sound could be trimmed, and you might not notice the difference because the volume is so low. Bitmaps You can reduce the file size impact of bitmaps in several ways. First of all, consider not using bitmaps at all. Although this might seem like a flippant tip, it’s worth thinking about. Of course, you should avoid any unnecessary raster graphics (.jpg, .gif, .bmp, and so on) because each pixel’s color is saved in the file (unlike with vector graphics, which store only the math necessary to redraw the shapes). However, certain types of images, such as photographs, only work as bitmaps. It’s not always a matter of choice. In addition, if you want a bitmap with transparency (also called an alpha chan- nel), .png is the only alternative. One big warning: Using Modify, Bitmap, Trace Bitmap does convert a bitmap into all-vector shapes. However, you should use this feature only
  3. File Size Considerations 413 when the bitmap contains clear and bold sections. If you find it necessary to set the Trace Bitmap dialog box to draw lots of tiny vector shapes instead of large, bold areas, as shown in Figure 22.5, you probably end up creating a vector version that’s larger than the original bitmap. People tend to think that vector graphics are small and bitmaps are large, but taken to an ex- treme, vectors can be quite large, too. Therefore, use Trace Bitmap only when the content of your image file is better served as a vector—that is, it contains bold geometric shapes. Of course if you’re trying to achieve a par- ticular special effect, Trace Bitmap can be used—if you keep in mind the potential file size impact. FIGURE 22.5 Using Trace Bitmap on a photo- graph would require such small val- ues for Threshold and Minimum Area that the image would increase in size. Importing High-Quality Media and Then Compressing Them Let’s review the difference between the bitmap export options. Although it might seem counterintuitive, it’s best to start by importing the highest-qual- ity sound, video, and bitmapped graphics possible. This certainly adds to the file size of your source .fla, but you can enable Flash to do the com- pression before publishing your movie. Either through the properties for in- dividual sound and bitmap items in the Library or through the Publish Settings dialog box, you can control how much Flash compresses your me- dia. For example, instead of converting an image into a compressed .jpg before importing it into Flash, try to start with the best-quality uncom- pressed .bmp or .png file. After it’s imported, you can specify how Flash is
  4. 414 HOUR 22: Minimizing File Size to compress it upon export. This way, you can always decide how much to compress it. If you start with something that’s already compressed (and therefore lower quality), you can’t make it any better inside Flash. High- quality sounds should start as .wav or .aif format. (MP3s are already com- pressed.) Raster graphics should be .bmp, .png, or .pct format. Note that .jpg files are always compressed at least a little bit, and .gif files always have 256 or fewer colors. However, if you have a sound or an image that’s already compressed (such as an .mp3 or .jpg file) and either you don’t have access to a better-quality original or you’re confident that the current compression is ideal, you don’t need to first convert it to another format. For example, you might have used the Selective JPEG Quality feature in Fireworks to make a great-look- ing and small JPG. In these cases, import the image as is, but make sure that Flash doesn’t recompress it. For imported compressed images, you see the option Use Imported JPEG Data in the Library item’s properties. Using this option prevents Flash from recompressing the file. The only time to recom- press an image that’s already compressed is when you have no access to the original. Compressing a compressed image brings the file size down, but the quality is lower than if you had simply compressed it to the same level once by starting with a high-quality original. Using the Bandwidth Profiler Now that you understand how to manage file size by compressing audio and bitmaps and using certain drawing techniques, you need to measure the impact of each. Even if you know audio adds to file size, you still might want to use it. Your decision needs to be based on how much file size the audio adds. If it means the user waits a couple extra seconds, adding audio might be worth it. However, if adding a piece of music means the user waits 10 minutes, you probably shouldn’t use the music. To decide whether a particular media element is worthwhile, you need to know how much it affects file size. The Bandwidth Profiler helps you assess exactly how much each media element adds to a file’s size. Basically, you try out a file size-re- duction technique such as compression, and then use the Bandwidth Pro- filer to judge how much the change helped. If you make another change, you use the Bandwidth Profiler again to measure the improvement. Previ- ous sections taught you how to identify ways file sizes grow; this section teaches you how to measure the impact. Turning on the Bandwidth Profiler is easy, but deciphering the data it pro- vides is a bit tricky. The following task introduces you to the basic features of the Bandwidth Profiler.
  5. File Size Considerations 415 In this task, you learn how the Bandwidth Profiler can help you assess TRY IT YOURSELF ▼ how a movie might play over the Internet. Follow these steps: Use the Bandwidth 1. Download the file keyframing.fla from the publisher’s website. Use Profiler to Judge Test Movie by pressing Ctrl+Enter. Download Times 2. As the exported .swf plays, select View, Bandwidth Profiler (or press Ctrl+B). This is an option in the Test Movie Flash Player, not the au- thoring tool, so you only see it while you’re testing. 3. The Bandwidth Profiler provides information in the top section while the movie plays below, as shown in Figure 22.6. You see data on the left, and a graph on the right. FIGURE 22.6 Vital statistics for an exported .swf are shown in the upper-left area of the Bandwidth Profiler. 4. Look at the first section of data called Movie. Most of this information is simply a recap of the settings you can change in your source movie such as dimensions and frame rate. In addition, you see two values whose numbers vary: Size (or file size) and Preload. When we tested the movie keyframing.fla, we got a file size of 9KB (or exactly 9,292 bytes). Later, when you attempt to optimize this file, you see whether the size is reduced. Preload displays how many frames must preload and how long that takes before the movie starts playing. Of course, this depends on your user’s Internet connection. The Band- width Profiler can make estimates based on different connection speeds, such as the preload time based for a modem settings (found under the menu View, Download Settings).
  6. 416 HOUR 22: Minimizing File Size ▼ TRY IT YOURSELF 5. Select View, Download Settings. Notice one of the modem types has Use the Bandwidth a check mark, 56K by default. Change this to 14.4 for 14.4Kbps Profiler to Judge modems and you see the Preload setting change from less than 1 Download Times second to about 4 seconds! 6. Select View, Download Settings, Customize, which opens the Custom Download Settings dialog box, as shown in Figure 22.7. Here, you can modify the presets or create your own. Add an option for the common cable modem bit rate of 1.5Mbps. In the sixth field, change User Set- ting 6 to read 1.5Mbps (Cable), and the number in the bit rate col- umn to 187000. Click OK. FIGURE 22.7 The Custom Down- load Settings dialog box enables you to simulate any Inter- net connection speed. 7. Select your new setting from the menu View, Download Settings. You should see the preload time reduce to nearly nothing. 8. The Bandwidth Profiler enables you to simulate how long a movie takes to download at the selected bit rate. Select View, Simulate Download. The movie starts over, and you see a green progress bar move across the top of the graph. Change the bit rate to 14.4 by selecting View, Download Settings, and try Show Streaming again. Even with this rela- tively basic movie, the current-frame marker in the graph catches up to the green progress bar and must occasionally wait for the content to download. This isn’t desirable, but it’s an accurate representation of how this movie looks on a slow connection. You learn ways to address this in the next task, “Reduce a File’s Size with the Bandwidth Profiler’s Help,” but for now you’re just learning how to identify problems. 9. In the View menu, select Frame by choosing Frame Graph (or press Ctrl+F). The graph shows a vertical bar for the file size of each frame’s contents. A tall bar means a frame has more data. The red horizontal line represents the sustained data transfer rate the current bit rate can maintain. In other words, if a frame’s bar is higher than the red line, Flash might need to pause at that frame while it down- loads. For example, in the keyframing.fla file, you notice relatively
  7. File Size Considerations 417 high bars at the beginning and through Frame 15. This makes sense. TRY IT YOURSELF ▼ Close the test movie, and look at the source file. After Frame 15, little Use the Bandwidth new content is introduced. The lack of new data means less to Profiler to Judge download (see Figure 22.8). Download Times FIGURE 22.8 After Frame 15, little new content appears onscreen until Frame 26. This means most data is downloaded by then, as you see in the Bandwidth Profiler. NOTE Deciphering Bits, Bytes, and Kilos In the preceding task, you specified 187,000 bytes per second for a 1.5Mbps cable modem. This was calculated based on modem speeds listed as “kilobits per sec- ond” (or, in the case of 1.5Mb cable connection, that’s 1,500,000 bits per second). Computer file sizes are often displayed in kilobytes or megabytes, not bits. Because 1 bit is one-eighth the size of a byte, you can convert bits to bytes by dividing by 8. Therefore, 1,500,000 bits per second is the same as 167,000 bytes per second. A 320KB image downloads in 2 seconds on a 1.5Mbps connection (1500Kbps / 8 = 167KBps; therefore, a 320KB file downloads in about 2 seconds at that rate). Another issue, however, is the fact that an Internet connection might not download at a consistent rate. Note the presets in the View, Download Settings menu for 28.8Kbps modem and 56Kbps modem are lower than what you would expect (2,400 and 4,700 instead of 3,600 and 7,000). That’s because the Flash presets are padded to more accurately represent an actual modem download speed. Gener- ally, you don’t have to do a lot of math. In this case, however, doing the math might be interesting. Use the Bandwidth Profiler’s Simulate Download option to watch how the movie plays. Analyze the movie frame-by-frame by scrubbing to view which frames are exceeding the red streaming limit. Just because a vertical
  8. 418 HOUR 22: Minimizing File Size line is above the red line doesn’t necessarily mean playback pauses at that frame. When possible, Flash starts to download frames before they are en- countered. For example, several frames might not involve any onscreen changes, but Flash is still downloading. While displaying these frames, Flash can start to download frames from later in the movie. Frames that have no visual changes don’t take long to download; therefore, Flash can concentrate on downloading future frames. This behavior is called advance streaming, but you can think of it as buffering. The Bandwidth Profiler has an option to show such streaming behavior in a graph that is similar to the Frame by Frame Graph view. When you select View, Streaming Graph, you still see each frame’s vertical box. Each frame is shown as alternating light and dark gray boxes. The red horizontal line rep- resents the maximum data that can be transmitted in the time one frame takes to play (that is, 1/12 second if you have a frame rate of 12 fps). If the first frame (dark gray,) can download in less than 1/12 second, you see Frame 2’s bar in dark gray stacked on top of Frame 1’s light gray bar. For example, open the keyframing.fla file again, and use Test Movie, select View, Streaming Graph, and select View, Download Settings, 56K. As you click on any of the first several gray or black rectangles, each of the first 13 frames takes 1/12 second or longer to download. Then in the time it takes to play Frame 28 or 29, Flash can download more than two frames (see Figure 22.9). As a result, the entire 60-frame movie is completely down- loaded in the time it takes 25 frames to display. Select View, Show Stream- ing for a view of this effect in real time. FIGURE 22.9 The Streaming Graph view (not Frame by Frame Graph view) dis- plays how quickly Flash preloads upcoming frames.
  9. File Size Considerations 419 The Bandwidth Profiler is very useful. However, it doesn’t fix problems; it only helps you discover problem areas. Ideally, you should avoid making your file too large in the first place. The Bandwidth Profiler is worth learn- ing to use, but it’s only for identifying problems that could be avoided. The following task steps you through a scenario of using the Bandwidth Profiler to help identify a problem and solve it. In this task, you use the Bandwidth Profiler to help improve a file’s size. TRY IT YOURSELF ▼ Follow these steps: Reduce a File’s Size 1. Open the same movie, keyframing.fla, you downloaded for the last with the Bandwidth task. Immediately determine the total size of the exported movie. Run Profiler’s Help Test Movie, and look at the data at the top-left area of the Bandwidth Profiler (press Ctrl+B if it’s not visible). For example, we get 10,746 bytes for the total size. Write down the number you get as a reference for later. 2. Close the movie you’re previewing. Select File, Publish Settings, and then select the Flash tab. Notice the JPEG Quality slider. Move that all the way to the left (the lowest quality), and click OK. 3. Test the movie again to see the change in file size that results from using compression. You shouldn’t see any change because JPEG com- pression is applied only to raster graphics, and this file has none. If this file had raster graphics, you would likely see this change made the file smaller but lowered its quality. 4. The change you make in this step causes a difference—you’re going to optimize the curves in every drawn shape. Unlock all the layers. Click the Edit Multiple Frames Onion Skin option, which enables you to select multiple frames. Now select the Modify Onion Markers menu, and pick Onion All, as shown in Figure 22.10. Finally, click the Stage, and then use Select All by pressing Ctrl+A. Choose Modify, Shape, Optimize, slide the Smoothing scale all the way up or type in 100, and select both option check boxes, as shown in Figure 22.11. Click OK, and you should eventually see a message concerning how much optimizing took place. When we tried this, we saw a 39% reduc- tion in the number of curves. 5. Use Test Movie, and notice the improvement in the file size. We get 6,730 bytes, which means the file is about 2,500 bytes smaller. It’s not a whole lot, but it’s something. What’s more, the image looks no worse. Notice the s in Flash, and the sparkles have changed.
  10. 420 HOUR 22: Minimizing File Size ▼ TRY IT YOURSELF Reduce a File’s Size with the Bandwidth Profiler’s Help FIGURE 22.10 To select every frame, choose Onion All after the Edit Multiple Frame option is set. FIGURE 22.11 Using Optimize reduces the file size by simplifying the shapes. Although the big lesson from this task might be that using Modify, Optimize can often reduce the file size by simplifying shapes, you’re still in the stage of finding problems. The Bandwidth Profiler helps find the problems, not necessarily fix them. You can find a related feature by selecting File, Publish Settings to open the Publish Settings dialog box, selecting the Flash tab, and clicking the option Generate Size Report, as shown in Figure 22.12. The next time you export the movie by using Test Movie, you see an all-text version of the data from the Bandwidth Profiler appear in the output window. In addition, you find a text file with the same prefix as your movie’s name and in the same folder with the same contents. This provides a permanent record of the data you find in the Bandwidth Profiler.
  11. File Size Considerations 421 FIGURE 22.12 The Publish Settings dialog box op- tion Generate Size Report exports a text version of data gathered from the Bandwidth Profiler. The keyframing.fla example still pauses periodically during the first 20 frames when you simulate a 14.4Kbps modem. If your target user would have that type of speed, and you can’t find any other way to reduce the file size, you have to resort to using a preloader, which loads all or part of the movie to your user’s memory before playing it. The following task shows a quick way to do that. To get a sense of how the Bandwidth Profiler works, in this task, you cre- TRY IT YOURSELF ▼ ate a basic preloader to pause playback on the first frame of a movie until Use a Preloader in most of the movie is downloaded. Follow these steps: the Bandwidth 1. Open the keyframing.fla file that you downloaded earlier this hour. Profiler It’s already set to publish as AS2.0, so the following code works. 2. Select Insert, Scene. Select Window, Other Panels, Scene, and use the Scene panel to rename the new scene Preloader. To rename it, double-click the current name (Scene 2), and then drag the scene or- der so Preloader is on top. 3. Click the first frame of the Preloader scene’s Timeline, and insert two additional keyframes by pressing F6 twice. 4. Select the second keyframe, open the Actions panel, and type the fol- lowing code: if(getBytesLoaded()
  12. 422 HOUR 22: Minimizing File Size ▼ TRY IT YOURSELF Translated, this means if the size of the bytes loaded is less than the Use a Preloader in size of the bytes total, then it goes back to Frame 1 and loops, where the Bandwidth it continues to reenter Frame 2 with this script. Profiler 5. So that the user can see it progress as he’s stuck in this screen, go to Frame 1, and place some text onscreen. With the text selected, use the Properties panel to set the text block to Dynamic Text, and give it the instance name progress_txt. Now you have to put a mes- sage in that field. 6. Select the first keyframe, open the Actions panel, and type the follow- ing code: percent = getBytesLoaded()/getBytesTotal()*100; percent=Math.floor(percent); progress_txt.text=percent+”%”; These three lines could be consolidated to one, but it’s easier to read this code as three lines here. First, you calculate the exact percentage downloaded and store it in a homemade variable called percent. Then, you set percent to the “floor” of percent, meaning the nondec- imal portion. Finally, the last line populates the text field with the value of percent plus the % symbol. 7. Run Test Movie, and with the Bandwidth Profiler, select View, Simulate Download. You see the percentage display increase until at 100%, and then the rest of the movie plays, as Figure 22.13 shows. FIGURE 22.13 While the content downloads, the movie is stuck in the first two frames of the first scene, where the user can see the percentage downloaded.
  13. File Size Considerations 423 The preloader you built in Hour 21, “Designing a Website to Be Modular,” is more sophisticated than the preloader you created in the preceding task. However, this was a good opportunity to use the Bandwidth Profiler. Improving the Download Experience You never hear someone say they enjoy waiting for Flash movies to down- load, so anything you can do to improve the experience is worth consider- ing. For example, in the previous example, a user might find something else to do while the movie preloads. In that case, he could actually miss the en- tire animation if he didn’t get back right in time. Perhaps a better design would be to insert a third frame in the Preloader scene (where the user won’t reach until it’s fully loaded), and a stop() script plus a button la- beled Begin. When the user clicks it, then he proceeds to the main anima- tion. Another idea is to modularize your movie by using the Loader and Sound classes (introduced in Hour 21). Sometimes it’s fine to keep every- thing in your main movie and have the user wait for it all, as in the previ- ous task. The advantage is that after it’s all downloaded, there are no more delays. However, when you have a ton of media, it makes more sense to spread out the delay so every time the user requests an image or sound, only then does he have to wait for it to download. Besides spreading out the delays, some users might not want to see every bit of content, so there’s no reason to force them to sit through a download. Both these tips are general, but you can even steal ideas from real life. Think about those coloring placemats restaurants often give kids. Some Flash sites create a simple puzzle or interactive quiz to placate users during the initial download. The point is if you make these considerations at the start of your project, you can usually hide or minimize the negative side of slow downloads.
  14. 424 HOUR 22: Minimizing File Size Summary This hour, you studied two ways to reduce the file size of your Flash movies so they download faster. The Bandwidth Profiler and the Generate Size Report option enable you to analyze your movies in several ways. You can use them to simulate download speeds and identify areas in your movies that need extra attention. Next hour, you continue the optimization process by concentrating on performance. Q&A Q. What’s the ideal file size for a movie? A. The best answer is “no bigger than it has to be.” Consider, too, that you can cover up a long download time in creative ways. Of course, you could use a percentage display, as you did in the previous task, “Use a Preloader in the Bandwidth Profiler.” Better than that, you can occupy your users with some interactive content. Make them watch something small but interesting while they wait for the bulk of the movie to down- load. There are many ways to do this successfully. Finally, consider us- ing the modular technique of the class discussed in Hour 21. That way, users have to wait for Loader to download only the portions of your site they request. Q. I used Modify, Shape, Optimize, and it sure cut down the file size, but my image doesn’t look good. What should I do? A. If the result of using Modify, Shape, Optimize is unsatisfactory, don’t use it. Try this option, and weigh the file size savings against the sacri- fice in the image’s quality. Often, an undesirable result isn’t as bad as it appears. Consider that in the final movie, the graphic you’re judging might only be onscreen for a fraction of a second. The bad quality might not matter in that case. Q. In the Flash tab of the Publish Settings dialog box, I found the option Compress Movie. What is this? A. It’s a way Flash compresses your actions. You learn more about it in Hour 24.
  15. Workshop 425 Q. My source .fla file is huge! Even after I deleted unused Library items, the file is much bigger than it should be. Why? A. When you import media into a Flash movie, the file size grows. When you delete the media, the file doesn’t go back down in size. However, you can select File, Save and Compact to effectively clean up the file. It’s almost like defragmenting a hard disk. Incidentally, a big .fla is not necessarily a problem for the user. It’s the .swf that counts. Workshop The Workshop consists of quiz questions and answers to help you solidify your understanding of the material covered in this hour. You should try to answer the questions before checking the answers. Quiz 1. If you reduce a file to half its file size, how fast does it download? A. This is impossible to calculate because everyone’s connection speed varies. B. Twice as fast as it would otherwise. C. This is impossible to calculate because you need to know the movie’s dimensions (height and width). 2. Breaking apart text makes your file size A. Smaller. B. Larger. C. It has no effect on file size. 3. The Bandwidth Profiler can simulate how a movie plays on a slow computer. A. True. Set your computer’s processor speed in the View menu. B. False. The Bandwidth Profiler only helps you judge a movie’s size and how fast it downloads. C. True. However, you have to select View, Simulate Computer.
  16. 426 HOUR 22: Minimizing File Size Quiz Answers 1. B. Answer C is false because the download speed of Flash movies doesn’t have anything to do with their dimensions. Answer A is not entirely false because you can’t say how long a file take to down- loads. However, if you cut the file size in half, you can certainly say the download goes twice as fast. Consider if you ordered a half-sand- wich—it would take you half as long to finish it as it would take you to eat a whole one. 2. B. The file size usually increases because Flash stores all the curves in every character of the text. 3. B. The Bandwidth Profiler judges file size and download perform- ance. If the question referred to a slow connection rather than a slow computer, Answer A would be correct.
  17. HOUR 23 Optimizing Performance After you explored shaving bits and bytes off your movie last hour, this WHAT YOU’LL LEARN IN hour you learn what you can do to remove excessive demands on the THIS HOUR: user’s computer to make the movie playback smoother. The frame rate you . How choosing the most set in Flash’s document properties is more of a top speed that Flash doesn’t appropriate effect can exceed. When the user’s computer can’t keep up, Flash either drops frames increase playback per- or plays at a slower frame rate. This hour you learn how to avoid both so formance your movie plays well and consistently on a wide variety of computers. . How to measure actual frame rate Measuring Performance . How to remove unnec- essary special effects to Although inconsistent playback (that is, where your movie plays at differ- improve performance ent speeds on different computers) is a bad thing, the real goal in this hour is to improve performance throughout your movie so it usually plays at the given frame rate. Unfortunately, Flash doesn’t ship with a Performance Pro- filer, where you can simulate performance on other machines. Flash cre- ators are given only a range of tips based on experience as well as a little superstition. Naturally, if you test your movie after each change, those changes that cause a huge drop in performance might pop out. Not only is this approach inconvenient, but you’re not likely to see incremental slow- downs that, in the end, all add up to significant performance hits. The ap- proach we suggest is to understand what effects are costly as far as decreasing performance and adopt a set of best practices to avoid (or use them sparingly). It doesn’t hurt if you have a way to measure performance, so we start by showing you how to use a little “fps meter” tool.
  18. 428 HOUR 23: Optimizing Performance ▼ TRY IT YOURSELF In this task, you learn how to use a simple frame rate. Follow these Use a Custom steps: Performance 1. Download and open the file fps_calculator.fla from the pub- Meter to Calculate lisher’s website. If you have a movie you’ve created that you’d like to Frame Rate test, open it as well. Otherwise, download the performance_test.fla file, also. 2. From the Stage of the file fps_calculator.fla, select and copy the instance of the fps_AS2 symbol (or the fps_AS3 symbol if your movie uses AS 3.0). 3. Go to your test movie (or the file performance_test.fla), and insert a new layer. Paste the fps_AS2 symbol you just copied from the other file into the new layer. 4. Select Control, Test Movie. The fps meter shows two numbers: The top one is an average frame rate, and the bottom number is the cur- rent frame rate. The value for the average is much more stable, but doesn’t readily show when the frame rate is being taxed temporarily. The dot is a button that resets the average monitor in case you want to start measuring a portion of your movie. If you’re running my performance_text.fla, notice that you should see the frame rate drop significantly when you click the button labeled Tax It Now be- cause it makes a complex animation with lots of alpha effects visible. 5. When you’re finished with the fps meter, you don’t have to delete it (though you can). You can turn its layer to Guide by choosing Modify, Timeline, Layer Properties. This way you can turn it back on if you have something else to test. Now that you have the fps meter, you can use it in your own projects. You can even use the fps meter to confirm the claims made during the rest of this hour because we’re about to cover various known performance issues in Flash. Impacts on Performance Now that you have a way to test claims (or your own theories) of perform- ance hits, the following includes some guidelines that should help you en- sure snappy playback.
  19. Impacts on Performance 429 Being Creative First, you need to find creative ways to make your movies look like they’re performing well. A lot of people use high frame rates, tweening, and spe- cial effects as crutches. You can actually make a frame-by-frame animation with just a few keyframes by manually repositioning your graphics be- tween frames and not using tweening at all. If you concentrate on the mes- sage you’re trying to convey to your viewers and fashion every frame meticulously, you probably end up with fewer frames, and that means bet- ter performance. Avoiding Gratuitous Special Effects In previous hours, you learned how unnecessary special effects can distract users from your core message. However, another reason to avoid gratuitous special effects is that having too many effects can cause a movie to play slowly. For example, it might not be necessary to rotate and motion tween each piece of text that appears onscreen. Maybe this is interesting for the first block of text, but it can get tiring to wait for each to do its animation. Plus, if a user’s computer slows down for each tween, the effect is even more disruptive. Although a motion tween involving a change in the Alpha effect might be necessary to communicate a particular message, this kind of tween should be used with caution. Not only does the computer need to display the ob- ject that’s moving, but it also needs to display a semitransparent version of the object, which means it must display the graphics underneath the object. Simply put, this means slower machines might not be able to keep up with the desired frame rate. Often, an Alpha effect isn’t even needed. For exam- ple, if your background is white, a simple Brightness effect looks the same and performs slightly better than an Alpha effect. Another significant performance hit that can often be avoided involves tweens that scale, move, or change the Alpha setting of a bitmap. Generally, Flash does not excel in the display of bitmaps. Changing the size of a bitmap makes the computer do a lot of work. Even if you have a fast ma- chine, you can see this behavior by first setting the frame rate to a high value (such as 60 fps), and then performing a simple motion tween on a bitmap. Select Control, Play (not Test Movie) to watch your movie play in- side Flash. Then, change the scale of the bitmap on either the keyframe or the tween, and play it again. You should see the actual frame rate drop dur- ing the tween that involves scale.
  20. 430 HOUR 23: Optimizing Performance Other special effects, such as Filters, can slow down performance, too. One way to preview such performance hits is by temporarily setting the frame rate very high (at least 60 fps), and then testing before and after you try dif- ferent approaches to see how they cause the movie to slow or play in a jerky manner. Keep in mind the suggestion given earlier in this section, and simply avoid unnecessary special effects. If you really need to use an effect, go ahead. Just be careful with those that cause the movie to slow down be- cause they might cause your users’ computers to slow down even more. Avoiding Streaming Sounds When you place sounds in keyframes, you have a choice between the Sync settings, Event and Stream. You should generally use Event or one of the other event-like choices, Start or Stop. These have the least impact on per- formance. Stream is useful when you need synchronization to be main- tained. When you use Stream sounds, you can hear the sounds play as you scrub the Timeline. Stream sounds are comparable to Graphic symbols, whose animation you can also preview when you scrub. The disadvantage to Stream sounds, however, is the visual parts of the movie are sacrificed when a computer can’t keep up. That is, Stream sounds are always syn- chronized, and if the computer can’t display the graphics in time, Flash drops visual frames to keep up with the sound. Therefore, Stream sounds can make the graphics appear to skip and jump. This is simply due to the fact that Flash never causes the sound to play slowly because it would sound funny if it did. Event sounds play as soon as they can. If the computer can keep up, these sounds play as expected (that is, when the appropriate keyframes are reached). Also, graphics displays as soon as they can. However, on slow machines, the graphics might take longer to display, so the sound might not stay in perfect synchronization. That’s not to say you can’t achieve a decent result with Event sounds. Consider cutting the sound files into shorter bits before importing them. You can place sounds in the Timeline so they line up closely with graphics. It still isn’t perfect, but at least no frames are dropped. If you don’t need critical synchronization, use Event sounds be- cause both the graphics and the sounds plays smoothly, but they might not be perfectly synchronized.
Đồng bộ tài khoản