# Audio fade in and out with an if/else statement

**URL:** <https://forum.kirupa.com/t/audio-fade-in-and-out-with-an-if-else-statement/271026>\
**Category:** Uncategorized\
**Created:** [September 17, 2008, 3:23pm UTC](https://forum.kirupa.com/t/audio-fade-in-and-out-with-an-if-else-statement/271026 "2008-09-17T15:23:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rynobot](https://avatars.discourse-cdn.com/v4/letter/r/bbce88/32.png) [@rynobot](https://forum.kirupa.com/u/rynobot)\
**Post date:** [September 17, 2008, 3:23pm UTC](https://forum.kirupa.com/t/audio-fade-in-and-out-with-an-if-else-statement/271026/1 "2008-09-17T15:23:15Z")

</div>

hey - trying to get an if/else statement working for an audio fade.

I want the audio to fade in if the volume is set to zero otherwise it means the volume is already set to 100 or the audio has been shut off. I can’t seem to get it working both ways.

here is the if/else i am trying to get working:

```auto
if (_global.musicplaying == true) {
		if (bgmusic.vol =! 100) {
			(_root.fade=!_root.fade) ? 1 : 0;
		} else {
			null();
		}
	}

```

and here is the actual code controlling the fade:

```auto
var vol = 100;
var step = 20;
var fade = 0;
onEnterFrame = function () {
	// set fade out
	if (fade) {
		vol = vol-step;
		if (vol<0) {
			vol = 0;
		}
		bgmusic.setVolume(vol);
		// set fade in
	} else {
		vol = vol+step;
		if (vol>100) {
			vol = 100;
		}
		bgmusic.setVolume(vol);
	}
};

```

Thanks in advance.
