# Sound - Actionscript Code

**URL:** https://forum.kirupa.com/t/sound-actionscript-code/27340
**Category:** flash
**Created:** [August 1, 2003, 8:01am UTC](https://forum.kirupa.com/t/sound-actionscript-code/27340 "2003-08-01T08:01:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![something369](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@something369](https://forum.kirupa.com/u/something369)
#### Post date: [August 1, 2003, 8:01am UTC](https://forum.kirupa.com/t/sound-actionscript-code/27340/1 "2003-08-01T08:01:04Z")

</div>

Hello,

I’m trying to fade in a sound that I am using as a background sound for a website. However, I can’t get the actionscript code right to complete the fade. Can anyone see the problem?

bgsound = new sound();  
bgsound.attachSound(“bgsound1”);  
bgsound.start(0, 1000);  
bgsoundvolume = 0;  
while (bgsoundvolume\<100) {  
bgsound.setVolume(bgsoundvolume);  
bgsoundvolume = bgsoundvolume+5;  
}

Any help is well appreciated. Thank you.

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 1, 2003, 8:06am UTC](https://forum.kirupa.com/t/sound-actionscript-code/27340/2 "2003-08-01T08:06:08Z")

</div>

use instead of “while(){}”

```auto
bgsoundvolume < 100 ? bgsoundvolume +=5 : bgsoundvolume = 100;

```

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 1, 2003, 8:27am UTC](https://forum.kirupa.com/t/sound-actionscript-code/27340/3 "2003-08-01T08:27:56Z")

</div>

[AS]var bgSound, bgSoundvol;  
bgSound = new sound();  
bgSound.attachSound(“bgsound1”);  
bgSound.start(0, 1000);  
bgSound.setVolume(0);  
this.onEnterFrame = function() {  
if (bgSoundvol\>=100) {  
this.onEnterFrame = null;  
}  
bgSoundvol++;  
bgSound.setVolume(bgSoundvol);  
};[/AS]

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)
#### Post date: [August 7, 2003, 7:52pm UTC](https://forum.kirupa.com/t/sound-actionscript-code/27340/4 "2003-08-07T19:52:07Z")

</div>

Thank you both for the help, especially claudio, your suggestion worked well.
