Yes, but he has created a separate Sound object for each sound (sound1 and sound2), so he's fine in that respect.

What would make this simpler, however, is to write a function that creates the sound objects based on the array, while also storing the initial volume for each sound. Here's an UNTESTED example:

// build the array based on linked sounds in the library ("catMeow" etc.):
var theSounds: Array = ["catMeow" , "dogBark" , "alienScream" , "doorCreak"]
// create a parallel array of sound levels for each sound:
var theVolumes: Array = [50,65,90,5];
// create a sound object for each array element:
for (i=0; i<theSounds.length; i++){
        // create the sound object and attach the sound:
        this [theSounds[i] + "SoundObject'] = new Sound();
        this [theSounds[i] + "SoundObject'].attachSound (this [theSounds[i]);
        // create a variable to store the initial volume for each sound:
        this [theSounds[i] + "SoundObject'].initVolume = theVolumes[i];
        // set the volume for this sound:
this [theSounds[i] + "SoundObject'].setVolume(this [theSounds[i] + "SoundObject'].initVolume);
}

Where "sound name" is the name of the sound object:
To play a sound, just use ("sound name").start.
To mute it, use ("sound name").setVolume(0);
To restore the volume, use ("sound name".setVolume("sound name".initVolume). You could construct a function for this where the only arg would be the sound name.

HTH

Marc Hoffman



At 08:33 AM 7/6/2007, you wrote:

Sound objects associated with the same movie clip share their
properties (volume, etc.), so if you change the volume through one of
them, the change will be reflected by others, too. That is because in
fact sound properties belong to movie clips and not the Sound objects,
and Sound objects only reflect the sound settings of the associated movie
clip.

  Attila

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
From:    [EMAIL PROTECTED] <[EMAIL PROTECTED]>
To:      flashcoders@chattyfig.figleaf.com <flashcoders@chattyfig.figleaf.com>
Date:    Friday, July 6, 2007, 4:44:25 PM
Subject: [Flashcoders] Controllingt he volume of multiple sound objects at the same time
--====----====----====----====----====----====----====----====----====----===--

Hey there. I am trying to control the volume of a number of sound objects that have their own individual volume levels. I want to be able to mute them or allow them to play at the volume that has been set for them. I was thinking that I could do this by storing the values in arrays and then looping through these each time the sound is muted/unmuted but I am sure there must be an easier way.
Any suggestsions v gratefully received :)

Here is what I have so far:
var sound1:Sound = new Sound(this);
sound1.setVolume(60);
var sound2:Sound = new Sound(this);
sound2.setVolume(20);

sound1.loadSound('an.mp3', false);
sound2.loadSound('another.mp3', false);


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to