Sound problem

Hey, ive been looking around for some tutorials on this, but all i can find is tutorials on how to play sound,

I have this ambient sound that i want to start upp with the site, no problem.
But i cant get it to stop playing, I need to have a button to stop and then start the sound loop again. It should be pretty basic i think.

Anyone know what to do?

Help much apretiated. :smiley:

You need to include a stopAllSounds on your button, e.g.

stop_btn.onRelease = function() {
 stopAllSounds();
};

To start your sounds using a button, you’d need to link the sound from your library first. Then, again within the button handler, create a sound object and attach the linked sound to it. This tutoiral should help you out http://www.kirupa.com/developer/actionscript/sound.htm

Sweet thx man. Got it working now. :smiley:

Well done :slight_smile:

Another thing, is there anyway i can get it to fade in at the start of the movie, and when i press the play button.

Code as it is now:

	kirupaSound = new Sound(this);
	kirupaSound.attachSound("forest");
	kirupaSound.start(0, 999);

You can use the sound.SetTransform method if you want to do it wholly in Actionscript. check out the Help file for more details.

Alternatively, if you just want a simple fade, select the frame containing your sound and then choose Fade In underthe Effects dropdown. You can also Edit the sound, then click along the wavelength to add your own effects.

Yeah, but with the action script im using now, im getting the loop file directly from to library. And i didnt find a place where i could add fade in effect directly on the library file.

So ill probably have to action script the fade in then? :slight_smile:

Have a read of this
http://www.actionscript.org/resources/articles/119/1/Dynamic-Sound-Fade/Page1.html

Nice tutorial. :slight_smile:

I followed the steps but for some reason it wont play the sound?

music = new Sound();
music.attachSound("forest");
music.start(0, 999999);
music.setVolume();
vol = 0;
fade = setinterval(fadeIn, 100);
function fadeIn() {
        vol += 5;
        music.setVolume(vol);
        if (vol>=100) {
                clearInterval(fade);
                step = 1;
                Fade = 0;
        }
}
_root.onEnterFrame = function() {
        if (Fade == 1) {
                vol = vol-step;
                if (vol<0) {
                        vol = 0;
                }
                music.setVolume(vol);
        } else {
                vol = vol+step;
                if (vol>100) {
                        vol = 100;
                }
                music.setVolume(vol);
        }
};

I cant really see why it shoudnt work.

Do you have the fla?

Well, I just copied that code into the first frame (didn’t bother with a button) and it fades in just fine.

Here is the fla. file

Sound test.fla

Hmmm wonder why mine doesnt work.

It works fine…but it’s very very faint…maybe you need to turn your speakers up? :slight_smile:

hehehe, thats soo wierd. Cause when i play it, nothing. i have my speakers on full too. :ear:

if i try to remove the fade code and just play the file itself it works fine.
I love it when this happens, :smiley: a mystery

Actually, I’ve solved the mystery - I’m playing your fla in Flash 6 :smiley:

I’ll play some more and see what I can come up with

Oh cool, Thx alot! :beam:

music = new Sound();
music.attachSound("forest");
music.start(0);
music.setVolume(0);
vol = 0;
fade = setInterval(fadeIn, 100);
function fadeIn() {
        vol += 1;
        music.setVolume(vol);
        if (vol>=100) {
                clearInterval(fade);
        }
}

You didn’t need all of that onEnterFrame gibberish and setinterval should be setInterval (since AS2 is case-sensitive).

Thanks…we got there in the end :slight_smile:

â– â– â– â–  example was riddled with spelling inconsistencies!! Gibberish was the polite word.

Three minds are better than two :stuck_out_tongue:

Just noticed that you’ll need to put the loops argument back into the start method.