ptg 312 Chapter 12 By default, Flash embeds audio files directly into the published (.swf) file. You have the option of loading audio files from a common Library. This gives you the advantage of using the same sounds in several Flash movies at the same time. For example, you create a Web site using fifteen separate Flash movie files, and each one uses the same back- ground music. Rather than embed the same sound fifteen times, you can simply load the sound, when needed, from a common Library. Shared libraries are simple Flash documents that are set up to share their files between several Flash movies. The process is easy, and the rewards are great, and you don't increase the file size of Flash movies using shared Library elements. Once you've created and defined a Flash document as a shared Library, you can use the items in other Flash movies without increasing the size of the Flash published .swf file. Loading a Sound from a Shared Library Create a Shared Audio Library Create a new Flash document. Add the audio files to the document's Library. They do not have to be placed on the Stage. Click the File menu, and then click Save. Use a distinctive name for the source document. Select an audio file in the Library. Click the Library Options button, and then click Properties. Select the Export For Runtime Sharing check box. ◆ If the check box is not available, clear the Import for runtime sharing check box. Enter a distinctive name for the Identifier field or use the default. Enter the name of the published document into the URL field. Click OK. Repeat steps 4 through 9 until all the audio files are correctly linked. Click the File menu, and then click Publish to create the Flash .swf file. Close the original source file. 11 10 9 8 7 6 5 4 3 2 1 4 5 6 8 7 9 From the Library of Wow! eBook ptg Chapter 12 Working with Sounds 313 Work with Shared Audio Libraries Click the File menu, point to Import, and then click Open External Library. Select the shared Library, and then click Open. The items in the external Library will be grayed out, indicated they are sharable items. Drag the audio files from the external Library to the Library of the active document. To display or change link properties for an audio, double- click the audio icon in the Library, click Advanced (if necessary), view or change link options, and then click OK. When you publish the Flash .swf file, the audio files will be drawn from the common Library, without increasing the size of the Flash movie. 4 3 2 1 External Library (Shared) 3 Linkage settings for audio Active Library 4 Did You Know? A Flash Library can be shared with other designers. Since a Library is sim- ply a Flash movie with Library ele- ments, you can create common libraries of often-used elements, and then give them to other designers. When you're working with two or more designers, this is a great way to maintain consistency on a complex project. From the Library of Wow! eBook ptg 314 Chapter 12 Sound is a great motivator. For example, a particular piece of music can make you happy, or it can make you sad. In addition, sounds can pull out childhood memories and stir emotions. Sound is a powerful tool, however, different people react differently to sounds, therefore it's important that you think carefully about the sounds you add to your movies. It's equally important to understand how you can control your movies using using ActionScript 3.0 code or ActionScript Behaviors in ActionScript 2.0. Using Audio with ActionScript Load a Sound from the Library with ActionScript 3.0 Create or open a Flash document (ActionScript 3.0). Click the Window menu, click Library to open the Library panel, and then select an audio file from the available Library items. Right-click (Win) or Command- click (Mac) the audio sound, and then click Properties. Click Advanced, if necessary. Enter a distinctive name for the Identifier field or use the default. Select the Export For ActionScript check box. Leave the other fields at their default values, and then click OK. Click Frame 1 in a layer. Click the Window menu, and then click Actions. Type the ActionScript code shown in the illustration: Click the Control menu, point to Test Movie, and then click Test. 10 9 8 7 6 5 4 3 2 1 2 6 4 9 8 3 5 From the Library of Wow! eBook ptg Chapter 12 Working with Sounds 315 Load a Sound from the Library with an ActionScript Behavior Create or open a Flash document (ActionScript 2.0). Click the Window menu, click Library to open the Library panel, and then select an audio file from the available Library items. Click the Library Options button, and then click Properties. Click Advanced, if necessary. Select the Export For ActionScript check box. Enter a distinctive name for the Identifier field or use the default. Leave the other fields at their default values, and then click OK. Click the Window menu, and then click Behaviors to open the Behaviors panel. Select a button object on the Stage or Timeline keyframe. Click the plus (+) sign, located in the upper-left portion of the Behaviors panel, point to Sound, and then click Load Sound From Library. Enter the name of the audio file in the Linkage ID field. Enter a unique name in the instance field. Select the Play This Sound When Loaded check box. Click OK. Select an Event to trigger the sound. If the audio file was added to a Timeline frame, the event field will be disabled. Click the Control menu, point to Test Movie, and then click Test. 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 10 11 12 9 13 2 3 8 14 From the Library of Wow! eBook ptg 316 Chapter 12 You can load an MP3 music audio file using a built-in Flash behavior. The advantage to this process is that the file is loaded when needed, and it never increases the size of the original Flash movie. Flash per- forms a calculation on audio files as they are loading. When it has enough of an audio file, it begins playing, while it continues to down- load the remaining information in the background. For large audio files, this cuts down on long wait times and keeps the visitor from becoming bored. Streaming MP3 files are not part of a pre-existing Flash movie, they're just available from a common location. Loading a Streaming MP3 File Load a Streaming MP 3 File with ActionScript 3.0 Create or open a Flash document (ActionScript 3.0), and then select a button object on the Stage. Open the Properties panel. Enter a distinctive name for the object in the Instance field, such as myButton . Click Frame 1 in the actions layer. Click the Window menu, and then click Actions. Enter the script as shown in the illustration: Click the Control menu, point to Test Movie, and then click Test. 7 6 5 4 3 2 1 1 4 6 5 See Also See Project 2, “Loading and Formatting Text” in the Workshops, available at www.perspection.com, for Action- Script 3.0 code to load external text. From the Library of Wow! eBook ptg Chapter 12 Working with Sounds 317 Load a Streaming MP 3 File with an ActionScript Behavior Create or open a Flash document (ActionScript 2.0), and then select a button object on the Stage or Timeline keyframe. Click the plus (+) sign, located in the upper-left portion of the Behaviors panel, point to Sound, and then click Load Streaming MP3 File. Enter the URL to the source MP3 file. Enter a unique name in the identifier field. Click OK. If you selected a button object, select an Event to trigger the sound. Click the Control menu, point to Test Movie, and then click Test. 7 6 5 4 3 2 1 2 3 1 5 4 Did You Know? You can stop all sounds using an ActionScript Behavior. Create or open a Flash document (ActionScript 2.0) that contains playing audio files, place a button object on the Stage, and then select it. Click the plus (+) sign in the Behaviors panel, point to Sound, and then click Stop All Sounds. Click OK. Select an Event to stop the sound. From the Library of Wow! eBook . Flash movies using shared Library elements. Once you've created and defined a Flash document as a shared Library, you can use the items in other Flash. common Library. Shared libraries are simple Flash documents that are set up to share their files between several Flash movies. The process is easy, and the