First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Kenny Bellew | Website: http://www.cowfly.com

How to Start, Stop and Loop a Sound Object

The syntax for starting a sound object is as follows:


It is commonly used as follows:


In this example, "firstSound" is the instance name of the sound object. The "secondOffset" refers to the amount of time, in seconds, that you would like to skip before starting to play the sound (this will be described in more detail later). The "loop" refers to the number of times you want the sound to loop. In the above example, this would start firstSound at its beginning position of zero and loop it 999 times.

Fig. 03: Example of starting and stopping

The syntax for stopping a sound object is as follows:


It is commonly used as in the following example:


Alternately, the ActionScript could also appear as:


In the first example above of stopping a sound object, the linkage identifier "firstSound01" is used. If the linkage identifier is not used, all sounds will stop. If only one sound should stop, it must be associated with a unique movie clip (container). How to associate the sound object to a movie clip is described in the next section.

For example, if you want to stop one of three sounds that are currently playing, and the sound was not assigned to a specific movie clip when it was defined, then you must specify the linkage identifier name as part of the stop command.

If you associate the starting of a sound with an event like a button press, it is a good idea to keep the sound from playing if it is already playing (unless you want multiple copies of the sound object playing at the same time). For example:

on (press) {
if (playing!=true) {

And when the sound is stopped by a button:

on (press) {

In the Flash example Fig04 below, notice how the sound object was defined (as described above the start buttons) and the result of pressing the various buttons (as described below the stop buttons). Press both green play buttons to have both sounds running at the same time. Experiment with the various combinations.

Fig. 04: Example of various effects of different ways of defining and stopping a sound object

» Level Intermediate

Added: 2004-10-12
Rating: 8 Votes: 31
» Author
Kenny Bellew is a technical writer and freelance flash programmer who specializes in Flash audio. He lives in Minneapolis, MN.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.