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.
|
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) { |
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.
|
» 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. |
Download (12927 kb) |
» Forums |
More help? Search our boards for quick answers! |
-
You must have javascript enabled in order to post comments.
Comments
There are no comments yet. Be the first to comment!