# Fading sound doesn't work

**URL:** <https://forum.kirupa.com/t/fading-sound-doesnt-work/326749>\
**Category:** Uncategorized\
**Created:** [January 9, 2012, 10:08pm UTC](https://forum.kirupa.com/t/fading-sound-doesnt-work/326749 "2012-01-09T22:08:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drpelz](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@drpelz](https://forum.kirupa.com/u/drpelz)\
**Post date:** [January 9, 2012, 10:08pm UTC](https://forum.kirupa.com/t/fading-sound-doesnt-work/326749/1 "2012-01-09T22:08:38Z")

</div>

Hi,

I have this problem when I try to fade in sound with the function below. It just doesn’t work and I can’t figure out where the problem is.  
I would like to fade in a looping sound but nothing happens. I appreciate any hint I can get to solve this problem. Thanks in advance.

this is used to play a sound via events

```auto

dispatchEvent(new CustomEventSound(CustomEventSound.PLAY_SOUND, Main.SOUND_AMBIENT, false, true, false, 999999, 0, 0, setSoundVolume));

```

this is the function to play a sound. the stop-function is almost identical to this one.

```auto

public function playSound(soundName:String, isSoundTrack:Boolean = false, fadeIn:Boolean = false, fadeOut:Boolean = false,
								  loops:int = 1, offset:Number = 0, volume:Number = 1):void {
			
			if (fadeIn) {
				tempSoundTransform.volume = 0;
			} else {
				tempSoundTransform.volume = volume;
				
			}
			tempSound = sounds[soundName];
			
			if (isSoundTrack) {
				if (soundTrackChannel != null) {
					soundTrackChannel.stop();
				}
				
				soundTrackChannel = tempSound.play(offset, loops);								
				soundTrackChannel.soundTransform = tempSoundTransform;
				
				if (fadeIn) {
					for (var i:int = 0; i < fadeInInc; i++) {
						tempSoundTransform.volume += 1 / fadeInInc;
						soundTrackChannel.soundTransform = tempSoundTransform;	
						if (tempSoundTransform.volume >= 1) {
							tempSoundTransform.volume = 1;
							
						}
					}
				}
				
			} else {
				soundChannels[soundName] = tempSound.play(offset, loops);
				soundChannels[soundName].soundTransform = tempSoundTransform;
				
				if (fadeIn) {
					for (var i:int = 0; i < fadeInInc; i++) {
						
						tempSoundTransform.volume += 1/fadeInInc;
						soundChannels[soundName].soundTransform = tempSoundTransform;	
						if (tempSoundTransform.volume >= 1) {
							tempSoundTransform.volume = 1;
							
						}
						
						trace("tempSoundTransform.volume " + tempSoundTransform.volume);
					}
				}
				
			}
					
		}

```
