Create a Flash Speech Synthesizer - Sound File
(Page 2 of 5 )
For this code to work, you need to have a sound file in the Library panel with the linkage identifier groovy. Although this is a standard requirement when using scripted sound, it is also the most likely cause of your sounds not playing if you get it wrong. Let’s go through it:
- After importing your sound file into Flash (with File-> Import -> Import to Library), right-click (Windows) orc-click (Mac) on the sound file asset in the Library. Select Linkage from the contextual menu that appears.
- In the Linkage Properties dialog box that appears, as shown inFigure 7-1, enter the linkage identifier groovy in the Identifier field. This can be any text string you want, but don’t make it too complicated, long, or unmemorable, because you need to use exactly the same linkage identifier (surrounded by quotes) in your code.
- Check the Export for ActionScript checkbox. The Export in First Frame checkbox will become selectable and checked when you do this. Leave Export in First Frame checked.

Figure 7-1. The Linkage Properties window, correctly filled in to define the groovy linkage identifier
As part of the process of compiling a SWF, Flash searches through your timelines to see when all your symbols are attached. It orders content in the SWF based on this. Thus, when the SWF is streamed over the Web, the symbols are loaded into the Flash Player in the order they are required. For symbols that are attached to timelines via scripting only, Flash will not see the symbols on the timeline during SWF compilation and does not add them to the SWF by default, in the assumption that they are unused. Checking the Export for ActionScript and Export in First Frame checkboxes overrides this default, and in doing so, you are telling Flash, “I will be using this symbol via scripting, so place the symbol in the SWF.”
However, this forces the Flash Player to download the sound before frame 1 is even displayed. A better approach is to place your sound in a movie clip and use the Sound.stop( ) command to prevent it from playing immediately [Hack #55]. Then place that movie clip on the frame of the main timeline in which you want the sound exported (i.e., the frame before you need the sound). But sound preloaders are not the subject of this hack, so let’s return to our previous setup.
 | If you've enjoyed what you've seen here, or to get more information, click on the "Buy the book!" graphic. Pick up a copy today!
Visit the O'Reilly Network http://www.oreillynet.com for more online content. |
Next: Repeat the Sound >>
More Flash Articles
More By O'Reilly Media