Search Tutorials
As stated earlier, wherever you attach the sound object, it becomes a child of that movie clip. Any call to a method of a sound object, such as setVolume, will affect all sound objects that are the child of that particular timeline. Therefore, to affect multiple sound objects independently, each sound object must be associated with its own unique movie clip. This can be an empty movie clip or one that is being used for something else. The result will be to group your sound objects by movie clip. It's very important to understand that this grouping is achieved in the way the sound object is defined - not by where it is defined. This is a common trouble spot when first starting to learn to use sound objects. For example, you may have figured out how to fade the volume for a sound object, but you find that it is also fading the volume for all other sound objects, too. The reason for this can usually be found in how the sound object was defined. The following is an example of how to assign a sound object as the child of a particular movie clip when the sound object is initially defined:
It is not necessary for the "firstSoundMc" movie clip to contain the ActionScript that starts the sound object. The "firstSoundMc" movie clip can remain empty. The sound object "firstSound" then becomes a child of "firstSoundMc". The only purpose of firstSoundMc is to serve as a container or association for the sound object. It is not necessary to create an associated movie clip for sound objects that only need to be started. It is needed when advanced methods such as setVolume and setPan are required for multiple independent sound objects, or when the need arises to stop one sound object while others continue. Once this is done, the methods of "firstSound" can be manipulated independent of the other sound objects. Ways by which the sound object's methods are called do not change. In other words, once you define the sound object as being attached to a particular movie clip, you never again need to reference that movie clip to control the sound object. Since, in our example, the sound object was defined on the _root level, calls to methods of the sound object would still only need to reference the _root path. For example, if you wanted to pan firstSound completely into the left speaker channel, the following would be used: _root.firstSound.setPan(-100);
// firstSound = new Sound(firstSoundMc); //Then, hypothetically, on a button in the movie some place
In the above example, if you panned firstSound, only the sounds associated
with the movie clip "firstSoundMc" would pan to the left. If you panned
secondSound with the above configuration, all sounds, regardless of where they
were defined or to which movie clip they were assigned, would pan to the left.
There is another way to associate sounds with specific movie clip instances. Define the sound object as before, except instead of indicating the name of a movie clip instance, use the keyword word "this" as follows: thirdSound = new Sound(this);
If the sound object is defined using the keyword "this", calls to the sound objects, such as setVolume() and stop(), will only affect the timeline (the movie clip) where the sound object is defined. Experiment with the Flash examples in Fig05b. Notice that the sound object, thirdSound, which is defined with the keyword "this", reacts identically to the sound object "firstSound", which was associated to a specific movie clip when it was defined on the _root timeline. Using the keyword "this" has advantages and disadvantages. One advantage is that, if the SWF file containing the sound object will be loaded into another movie using loadMovie, there is no risk of losing its association with the movie clip it was associated with when it was originally defined. The other advantage is that it is easier to configure (fewer steps). The disadvantage is that the path to the sound object must be used when calling it into action. If there are a lot of sound objects scattered about in numerous movie clips, it can become a tangled web.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|