# Dynamic fade sound (in/out)

**URL:** <https://forum.kirupa.com/t/dynamic-fade-sound-in-out/140360>\
**Category:** Uncategorized\
**Created:** [March 10, 2005, 11:33am UTC](https://forum.kirupa.com/t/dynamic-fade-sound-in-out/140360 "2005-03-10T11:33:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sWo0p](https://avatars.discourse-cdn.com/v4/letter/s/f0a364/32.png) [@sWo0p](https://forum.kirupa.com/u/sWo0p)\
**Post date:** [March 10, 2005, 11:33am UTC](https://forum.kirupa.com/t/dynamic-fade-sound-in-out/140360/1 "2005-03-10T11:33:01Z")

</div>

im curently working on a full flash site and i have a little script that fades in audio and has to fade out audio on button click… but there is something wrong…

this is how it works:

**frame 1:**

```php

music = new Sound();
music.attachSound("backsound");
music.start(0, 999999);
music.setVolume(0);
vol = 0;
fade = setInterval(fadeIn, 100);
function fadeIn() {
        vol += 3;
        music.setVolume(vol);
        reaches to 100
        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);
        }
};

```

**on button:**

```php

on (release) {
        (_root.fade=!_root.fade) ? 0 : 1;
}

```

(dont forget to lnk the MP3)

somehow i cant get this to work? :\*(
