Sonify Your Web Site:
Adding Interactive Sound
After creating a sound-only SWF file, you can begin to code a Web page for sound. Coding with the FlashSound API typically requires four steps:
- Create a FlashSound instance.
- Embed your SWF.
Copy and paste the complete code template
script file from Sonify.org (Windows users right click, Mac users option click, and save from the menu). Here's the script you need to add. Replace the pathto portion of the URL with the path to the script on your server.
Step 2: Create a FlashSound API instance
<title>Playing with the FlashSound API</title>
: Embed your SWF
Embed the SWF content at the end of the HTML document just before the closing <body> tag. To embed your SWF, add the URL of the SWF to the embedSWF() method. This embeds a 1 by 1 pixel hidden instance of the Flash Player in the document wherever you place the embedSWF( ) statement. For example:
web page content.......
The link starts the sounds when the user moves the mouse over the link and stops the sound when the mouse leaves the link. Use the TGotoAndPlay( ) method to play sounds in your SWF.
onClick = "return false">Hear a cool sound</a>
The TGotoAndPlay(targetpath, frame) method is the most common FlashSound API method for playing sounds. The method finds the specified movie clip in your embedded SWF, and then goes to the specified frame number or label and starts playing the movie clip from that point.
Clip target paths are much like URLs. For example, the URL "/products.html", indicates that the "products.html" Web page is in the root directory; the forward slash "/" means root directory. In Flash, the syntax, "/" represents the root timeline instead. So if you attach a movie clip with the instance name "coolsound" to the root timeline, the target path would be "/coolsound". This tells the Flash Player to find the movie clip with the instance name "coolsound" attached to the root timeline. For more information on target paths and slash syntax read "Understanding Slash Syntax Target Paths."
In the Creating Sound-Only Movies
section of this QuickStart, you added sounds to a movie clip with frames labeled "start" and "stop." The frame labeled "start" contained your sound. When the Flash Player plays this frame the sound plays. The frame labeled "stop" contains a stop sync sound command. When Flash plays this frame your sound stops. To create interaction, you tell the Flash Player which sound to control with the target path and whether to start or stop by playing the "start" or "stop" frame.