I am using sound files from the library, not URLs.
I am making a soundboard and have a button that plays background music. The reason I have a button instead of automatically playing on load is that there are a few different background musics to choose from, each with their own button.
I also have several other buttons that play sounds. I want the background music volume to lower to something like 0.3 while other sounds are playing. I believe I need to create a variable like soundCount that goes up when a sound plays, and decreases when the sound finishes playing (so that if there are multiple sounds playing at once, the background music won’t go back to normal until the count is at 0).
What’s the best way to set this up? I made the soundCount variable but I’m having trouble creating an event listener for when sound effect finishes playing.
To change the volume of a sound in AS3, you need to use the
SoundChannelandSoundTransformclasses:Keep track of total sounds in the background by incrementing your count during calls to
playand decrementing duringSOUND_COMPLETEevents. Add event listeners to other sounds’ channels so they can modifybackground‘s volume:Finally, modify the
SoundTransform‘svolumemember when the count is 0: