Browse DevX
Sign up for e-mail newsletters from DevX


FlashSound API: The Sound of Invisible Flash  : Page 9

Learn to use Flash to add interactive sound to your Web pages.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Sonify Your Web Site: Add Streaming Sound
Unlike download sounds, stream sounds do not require the movie clip approach. To create an Autostart stream sound, add a sound to the root timeline (on or after frame 5), add enough frames to the timeline to see the complete wave form of the sound and set the sync option to stream. Add some empty frames at the end of the timeline after your sound. An Autostart stream sound begins as soon as the Flash Player finishes buffering the stream sound (see Figure 18).

To keep things simple, I recommend placing interactive sounds and streaming sounds in different SWF files. Therefore you should have two SWF in your Web page, each with its own JavaScript instance name and embedSWF( ) statement.

Play, Stop, and Rewind Stream Sounds
The three FlashSound API commands useful for controlling stream sounds are TPlay(targetpath), TStopPlay(targetpath), and TGotoAndStop(targetpath, frame). The target path for the root timeline is "/".

Code to play a stream sound:

<a href="javascript://" onClick = "mysound.TPlay('/'); return false"> Play a Stream Sound</a>

Code to stop a stream sound:

<a href="javascript://" onClick = "mysound.TStopPlay('/'); return false"> Stop a Stream Sound</a>

Code to rewind a stream sound:

<a href="javascript://" onClick = "mysound.TGotoAndStop('/',1); return false">Rewind a Stream Sound</a>

The TPlay command starts playing at frame 1 or wherever the player was last stopped. The TStopPlay command acts like a pause button. If you call the TPlay command right after TstopPlay, the Flash Player resumes playback at the pause point. Although there's no explicit rewind command, the TGotoAndStop command is well suited for rewind because it moves the Flash play head to the specified frame and stops there until you tell the Flash Player to resume playback wth TPlay or TGotoAndPlay commands.
Figure 20.

Stream Sound Guidelines

Place stream sounds only on the root timeline. A stream sound in a movie clip always downloads rather than streams. You can change the size of the Flash buffers (preloads) before starting playback. Larger buffers reduce the chance of stream interruption, but also increase the delay before playback begins. The _soundbuftime property controls the number of seconds of sound that the Flash Player stores in the buffer. Set the _soundbuftime property to the desired number of seconds to override the default buffer time of five seconds. Add your ActionScript to a frame preceding your sound (see Figures 19 and 20)

The browser caches stream files; therefore, after a stream has played through completely once, the browser will retrieve the file from the browser cache rather than request it from the Web.

The FlashSound API has many other features. For example, you can create more complex types of interactions or audio applications. Download the full documentation and explore how you can add interactive invisible sound to your Web site.

Hayden Porter is a Web developer and musician with a special interest in Interactive Sound for the Web. He is a frequent contributor both as writer and forum moderator for www.sonify.org and maintains a Web design business, www.aviarts.com, in Akron Ohio. Reach him here.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date