Hello. Any help is greatly appreciated. I've worked hard to get this working by roaming the net forever, and it's working out great, except for one small final touch. I have two MP3s that I am playing as background music on my site. They stream automatically when the site starts, and it's working. The first one plays, when it's done, the second starts. Then it stops. I had a bit of a problem with the second one starting again (looping), so I added the last bit of code //my_sound.onSoundComplete = function () {my_sound.stop()// to stop that, and that is working fine. My problem is two fold. First, the stop button no longer works at all. It does nothing (and it worked fine before I added that bit of "my_sound.stop" code. If I remove that code, the stop button will work again, but the second MP3 goes back into loop mode.) What I'm wanting to accomplish is, in as simple code as possible, have the two MP3s play one after another, then stop. Of course the stop button would do it's thing, and with the start button, I need it to, once both MP3s have finished, "reset" itself so if you click on it after all MP3s have played, it will start over with the first MP3. Right now, if the first MP3 is playing and you hit start, it repeats the first MP3, and if you hit the start during the second MP3 playing, it starts the second MP3 again (which I like how that works.) but when they both finish, and there is no music, if you hit start, it replays only the second MP3, not the first. Make sense? I hope so, I can be confusing. Here is the code. Thanks alot! :-) //sound code// var my_sound:Sound = new Sound(); my_sound.loadSound("morningstar.mp3",true); my_sound.onSoundComplete = function () { my_sound.stop(); my_sound.loadSound("limpid.mp3",true); my_sound.start(); my_sound.onSoundComplete = function () {my_sound.stop() }; }; //code on start button// on (release) { my_sound.start(); } //code on stop button// on (release) { my_sound.stop(); }
try: // attached to a frame: var my_sound:Sound = new Sound(); var soundNum:Number = 1; my_sound.loadSound("morningstar.mp3",true); my_sound.onSoundComplete = function() { if (soundNum == 1) { my_sound.loadSound("limpid.mp3",true); soundNum = 2; } else { soundNum = 1; } }; // attached to your start button: on (release) { if(soundNum==1){ my_sound.loadSound("morningstar.mp3",true); } else { my_sound.loadSound("limpid.mp3",true); } } // your stop button's code is ok
Great! Thanks so much, it works! One tiny tiny thing, I've noticed if I stop the music, and then hit the start button (with the new coding) it pauses for a moment, the cursor actually stays a hand, and then might spin for a few seconds, before it begins to play. It's so not a big deal, but I didn't know if it was doing that because it had to reload the files each time, or what? It did not do that previously. But it works, so that's what matters!
change your button's code to the following and retest: on(release){ if (soundNum == 1) { if (my_sound.position<my_sound.duration) { my_sound.start(); } else { my_sound.loadSound("morningstar.mp3",true); } } else { if (my_sound.position<my_sound.duration) { my_sound.start(); } else { my_sound.loadSound("limpid.mp3",true); } } };
You are the greatest to help me out here. Seriously. Unfortunately, I'm not sure why but the last bit of code you just listed isn't working at all. It does nothing. I both typed it in, and copied it straight from here just to be sure. Thanks though!
yes, that's not going to work because your sound is streaming. try: var my_sound:Sound = new Sound(); var soundNum:Number = 1; my_sound.loadSound("morningstar.mp3",true); my_sound.onSoundComplete = function() { if (!soundStopped&&soundNum == 1) { my_sound.loadSound("limpid.mp3",true); soundNum = 2; } else if(!soundStopped) { soundNum = 1; } }; // start button: on(release){ if (soundStopped) { my_sound.start(); } else if (soundNum == 1) { my_sound.loadSound("morningstar.mp3",true); } else { my_sound.loadSound("limpid.mp3",true); } soundStopped=false }; // stop button: on(release){ my_sound.stop(); soundStopped=true; }
Thanks! Change the // }; // at the end of the start button to // } // and it's all a winner! I so appreciate your help! Feel free to check it out at www.nathanaaron.com, I just uploaded it. Thanks again, sincerely.
Don't see what you're looking for? Try a search.
|