the sound interface in flash uses the MovieClip hierarchy, i.e. each sound object is assigned to a MovieClip and controls all the sound in that clip.
you can assign a MovieClip to a sound object by passing the MovieClip as a variable to the sounds constructor.
for example if i have 2 MovieClips mc1 and mc2 were mc2 is nested inside mc1, i.e.
var mc1:MovieClip = root.createEmptyMovieClip(‘mc1_mc’,_root.getNextHighestDepth());
var mc2:MovieClip = mc1.createEmptyMovieClip(’mc2mc’,mc1.getNextHighestDepth());
i can create 2 sound objects for them sound1 and sound2:
var sound1:Sound = new Sound(mc1);
var sound2:Sound = new Sound(mc2);
the volume hierarchy works a lot like alpha in MovieClips, so:
if i set the volume for sound1 to 50 and the volume for sound2 to 100 sounds played with sound2 will play at 50%
if i set the volume for sound1 to 50 and the volume for sound2 to 40 sounds played with sound2 will play at 20%
now if you don’t send a MovieClip to the sound constructor that sound object will control the sound for _root, that means that it controls the sound for the whole movie
in your case all you need to do is replace this:
music = new Sound();
music.setVolume(25);
with this:
music = new Sound(musicplayer);
music.setVolume(25);
and get rid of this:
audio = new Sound();
audio.setVolume(25);
thanks for giving me a reason to finally learn how sound works in flash
good luck
|