# Help with Sound Fade Button

**URL:** <https://forum.kirupa.com/t/help-with-sound-fade-button/154962>\
**Category:** flash\
**Created:** [July 13, 2005, 9:27pm UTC](https://forum.kirupa.com/t/help-with-sound-fade-button/154962 "2005-07-13T21:27:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ace893](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@ace893](https://forum.kirupa.com/u/ace893)\
**Post date:** [July 13, 2005, 9:27pm UTC](https://forum.kirupa.com/t/help-with-sound-fade-button/154962/1 "2005-07-13T21:27:20Z")

</div>

I will be having BG music on my site and will have a simple on and off button for it without a volume option. I want it to fade out when turned off, and fade in when turned on.

This is in the first frame of the actions layer:

```auto
musicOn = 1;
this.onEnterFrame = function() {
	if (fadeIn01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume+5;
		if (myLoopVolume>99) {
			fadeIn01 = 0;
		}
	}
	if (fadeOut01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume-5;
		if (myLoopVolume<5) {
			_root.myLoop.stop("myLoop01");
			fadeOut01 = 0;
		}
	}
};

```

This is what I have to create the sound in a seperate frame:

```auto
musicOn = 1;
this.onEnterFrame = function() {
	if (fadeIn01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume+5;
		if (myLoopVolume>99) {
			fadeIn01 = 0;
		}
	}
	if (fadeOut01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume-5;
		if (myLoopVolume<5) {
			_root.myLoop.stop("myLoop01");
			fadeOut01 = 0;
		}
	}
};

```

And this is what I have attached to the button:

```auto
musicOn = 1;
this.onEnterFrame = function() {
	if (fadeIn01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume+5;
		if (myLoopVolume>99) {
			fadeIn01 = 0;
		}
	}
	if (fadeOut01 == 1) {
		_root.myLoop.setVolume(myLoopVolume);
		myLoopVolume = myLoopVolume-5;
		if (myLoopVolume<5) {
			_root.myLoop.stop("myLoop01");
			fadeOut01 = 0;
		}
	}
};

```

I will also attach a link to the file since it is too big to host I think.  
HERE IS THE FLA

Thanks for any help!!

ALSO: I will be loading this movie into another as an external movie. Do I need to change all the \_root identifiers to this? or \_parent?
