First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
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:

firstSound.start([SecondOffset,loop])

It is commonly used as follows:

_root.firstSound.start(0,999);

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:

firstSound.stop(["idName"])

It is commonly used as in the following example:

_root.firstSound.stop("firstSound01")

Alternately, the ActionScript could also appear as:

_root.firstSound.stop();

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) {
playing=true;
_root.firstSound.start(0,999);
}

And when the sound is stopped by a button:

on (press) {
_root.firstSound.stop("firstSound01");
playing=false;
}

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
(10 being the highest)
» 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!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: work2survive
» Title: Girl Walking 1kb
» Description: Walking girl, animation just takes 1kb, using high heels shoes, and fashion model attitude.
Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
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: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.