Recipe 17.8. Looping Sounds


Problem

You want to loop the playback of a sound.

Solution

Set a Loop value for the sound in the Property inspector.

Discussion

Flash allows you to loop sounds within your movies. This can be a great benefit to you, because you can create longer soundtracks without increasing your movie's file size. You can import a short sound file, add it to a keyframe as in Recipe 17.3, and then set the number of times you want it to loop. You can loop a sound only in whole number increments. For example, you can loop a sound three times, but not three-and-a-half times. And if you attempt to enter a non-integer value, Flash will prompt you to fix your entry.

In order to set the number of times to loop a sound, select the keyframe into which you have placed the sound, and then locate the Loop field in the Property inspector. By default, the loop value is 0. A value of 1 or less (including negative numbers) results in the sound playing once. Otherwise, the sound plays the number of times you specify, without any pause in between. The valid range of values for the loop value extends up to 2,147,483,647. If you enter a value greater than that, Flash will automatically reassign a value of 2,147,483,647.

Generally, looping works best with sounds that you have synchronized using either the Start or Event setting. Because of the way that the Stream synchronization works, Flash requires that you first create enough frames in order to play the sound. In most looping scenarios, this is not something you want to have to deal with. After all, usually you want looping sounds to continue to play regardless of whether the playhead is moving. Another problem with trying to loop sounds set to Stream is that the Flash movie's file size will increase.

Also, although looping sounds offer a way for you to add continuous sound to your movie, it is a technique that has been overdone and has become cliché. Don't let this completely deter you from implementing this techniqueif done carefully and with some careful consideration, it can have a nice effect. But a single, four-beat loop that continues for hours can often have the effect of aggravating users. If you are unsure of the effect of your musical selection, at least give the user the option to stop the sound. See Recipe 17.10 for more information on how to achieve this.

See Also

Recipe 17.3. Also see Recipe 17.10 for more information on how to stop a looping sound or how to restart it after it has been stopped.




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net