# Sound Fades

**URL:** <https://forum.kirupa.com/t/sound-fades/245843>\
**Category:** flash\
**Created:** [December 4, 2007, 8:24pm UTC](https://forum.kirupa.com/t/sound-fades/245843 "2007-12-04T20:24:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kdawg](https://avatars.discourse-cdn.com/v4/letter/k/e19b73/32.png) [@kdawg](https://forum.kirupa.com/u/kdawg)\
**Post date:** [December 4, 2007, 8:24pm UTC](https://forum.kirupa.com/t/sound-fades/245843/1 "2007-12-04T20:24:21Z")

</div>

I have a script using setInterval to audio clips in and out. fadeIn works right but fadeOut isn’t. Am I missing something? A typo?

```auto

bells = new Sound ();
bells.attachSound ("bells");

cricket = new Sound ();
cricket.attachSound ("cricket");

birds = new Sound ();
birds.attachSound ("birds");

var sound_iv:Number;
var sound_ov:Number;

function fadeIn (soundClip):Void {
    soundClip.start ();
    soundClip.setVolume (0);
    sound_iv = setInterval (function () {
        if (_vol == undefined) {
            _vol = 0;
        }
        _vol++;
        soundClip.setVolume (_vol);
        if (_vol == 100) {
            trace ("FadeIn done");
            clearInterval (sound_iv);
        }
    }, 10);
}

function fadeOut (soundClip):Void {
    soundClip.setVolume (100);
    sound_ov = setInterval (function () {
        if (_vol == undefined) {
            _vol = 100;
        }
        _vol--;
        soundClip.setVolume (_vol);
        if (_vol == 0) {
            trace ("FadeOut done");
            clearInterval (sound_ov);
        }
    }, 10);
}

fadeIn(birds);

```
