Flash CS3 music/sound question
I have a sound-related question that seems like it would be exceedingly simple to do, yet all my sound-related searches turn up either methods not viable in my version of Flash, or sound manipulation techniques that don't do what I need.
Here's the scenario: My flash animation has a background music that plays throughout, as well as sound effects that play at specific points in the movie. The background music should be playing from the start, but I need a button that will toggle the music on and off without disrupting the sound effects; it needs to turn on and off the background music specifically.
The file, "song.mp3", is in the same folder as the flash project.
I'm imagining the actionscript to accomplish this should look something like this:
songbutton.buttonMode = true;
var songBoolean:Boolean = true;
var bgm:Sound = new Sound;
if(songBoolean == true)
songBoolean = false;
songBoolean = true;
you're almost there, but not quite.
first, you should have your Sound play through a SoundChannel. Keeping your different sounds
distinct, played through separate SoundChannels is important, especially if you want to manipulate them separately.
the sequence is this: load the URLRequest ( the mp3) into the instantiated Sound Object, create a SoundChannel, and then have the SoundChannel play that Sound Object
the logic in your 'if' statement is good, it just now needs to reflect correct coding for a sound channel.
If you are expecting to actually just 'pause' the Sound, know that you can really only just stop it. it automatically 'rewinds' to the beginning. so when you start it again it will play from the beginning. if that is ok, fine. if not, you need to somehow take note of where the SoundChannel's position was when you stopped it, and then let it start up not from the beginnng, but from that new point.
you can accomplish that by just asking for the SoundChannel position, then telling it to start from that position.
here is some complete code i wrote a while ago that does all this. i updated the code to reflect the names that you have chosen to use.
hope that helps. let me know if anything needs clarification.