Sound - Actionscript Code

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.

use instead of “while(){}”

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

[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]

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