Starting and Stopping a Sound


Your Sound object has been created, and the sound has been attached. So why can't you hear anything yet? You can't hear anything because you haven't explicitly told the Sound object to start playing the sound. You have to use the Start method of the Sound object to make the sound start playing. This method has the following syntax:

 mySound.start([secondOffset, loop]); 

The secondOffset argument lets you start playing the sound at a specific point. The unit for this argument is seconds. If you have a 10-second sound, and you specify a secondOffset of 5, the sound starts playing five seconds into the sound. This argument is optionalif you don't specify a secondOffset, the sound starts playing at the beginning.

The loop argument also is optional. It enables you to specify the number of times that you want the sound to play. Flash can't loop the sound infinitely, but it can loop a large number of times99,999,999 times, to be exact!

Note

You can apply the Start method to your Sound object more than once. Each time you apply this method to the object, it starts playing another instance of the attached sound, much like the Event Sync plays multiple instances of the same sound on the timeline. Be careful if you provide the means to use the Start method in your movie because starting the Sound object repeatedly results in overlapping instances of the sound.


After you start a sound, you then can control its volume and pan using additional methods of the Sound object, which you learn more about later in this chapter. You also can stop a sound started with the Start method using the Stop method. The syntax for the Stop method is as follows :

 mySound.stop(["identifier"]); 

The Stop method of the Sound object has an optional identifier argument. This enables you to stop only one sound. If you do not use the identifier argument, the Stop method stops all sounds, including event and streaming sounds in the timeline. The next time a sound is triggered, either on the timeline or with a Sound object, it starts playing without any problems.

Exercise 18.3 Starting the Sound

You attached the sound, so now you have to start it.

  1. You should still have volume.fla open from the last exercise. Select frame 1 of the Actions layer in the Volume Controller layer. Attach the sound by adding the following line to the existing ActionScript in the Actions panel (see Figure 18.4):

     mySound.start(0,9999); 
    Figure 18.4. The finished ActionScript to create the Sound object, attach the sound, and start the sound.

    graphics/18fig04.gif

  2. Choose Control > Test Movie to hear your sound. (See Figure 18.5.) Close the Test Movie window and save your file.

    Figure 18.5. The movie plays the sound, along with some animation.

    graphics/18fig05.gif

When the movie played , you should have heard your sound start to play after a short introductory animation. The sound will loop 9999 times, if you listen to it long enough. You did not use the Stop method to make the sound stop playing because next you're going to learn how to use ActionScript to control the volume of the sound.



Inside Flash
Inside Flash MX (2nd Edition) (Inside (New Riders))
ISBN: 0735712549
EAN: 2147483647
Year: 2005
Pages: 257
Authors: Jody Keating

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