|
|||
| week 09b - final project, audio, drawing, loadmovie, preloader | |||
scripted audio : |
controlling sound in ActionScript References: Textbook pages 769-792 Sounds are often put inside Flash timelines, but this approach limits their use to the playing of that particular timeline. If you want sounds to play at arbitrary times, in response to user actions, it is best to control the sound from ActionScript. ActionScript provides complete control over sound in terms of start, stop, number of times a sound loops, pan position, and volume. Of course, if your application uses sounds, you need a source for the sounds. One option is to record your own, an often overlooked approach to getting the exact sound or dialog you need. Of course, there are many sounds on the Internet. Here are a few links that provide free and paid sounds:
|
|
| example : | play three different sounds This example flash file plays three different sounds, each one placed in a different position in the stereo field--left, center, right. The sound plays while the mouse button is pressed, but is cut short if the button is released.
|
|
| setup : |
make the sounds linkable to ActionScript The code from the above example attaches a sound from the library to an individual movieClip. It does this by creating a sound object, attaching a linked sound to this new object, and then sets the stereo pan position for sound. The sound is played when the user clicks and holds on the movieClip. The sound is stopped when the sound completes or when the mouse button is released. In order for this code to work, the sounds must have been imported into the library of the movie. In addition, each sound must be exported for use in ActionScript (the same process for atttaching movieClips in ActionScript). Once the sound is in the library, do the following:
|
|
| codewalk : | attach a sound to an individual movieClip Here is the code from one of the movieClips in the example:
load event: In this initialization code, the sound is attached from the library, and the stereo pan position is set. The first line creates a new sound object for this movieClip and assigns it to a variable arbitrarily name "soundObject". Sound objects are used to control sounds in ActionScript. If you wanted to have the sound object control all the sounds in the movie, you would leave out the "this" in the Sound() method. this.soundObject = new Sound(this); The next line of code attaches the sound "meow" from the library to the new sound object. As mentioned above, this code will only work if the sound is in the library, and its linkage has been set.
The next line sets the pan position of this sound object. -100 is full left, 0 is center, 100 is full right. this.soundObject.setPan(-100); The next line sets the volume of this sound object. 0 is silent, 100 is normal, 200 is the maximum this.soundObject.setVolume(100); press event: This code starts the playing of the sound attached to the specified sound object. If you wanted the sound to start at a point after the begining, use the number of seconds (can be fractional) after the start as the first argument, e.g. start(0.5). And if you want the sound to loop, put the number of loops in the second arguement; e.g. start(0.5, 6) which would start the sound 0.5 seconds after the beginning, and loop the sound 6 times. this.soundObject.start(0,2); release event: This code stops the sound.
|
| all materials on this web site © copyright 2004, Philip van Allen |
top |