# onEnterFrame means no sound for you!

**URL:** <https://forum.kirupa.com/t/onenterframe-means-no-sound-for-you/235644>\
**Category:** flash\
**Created:** [August 13, 2007, 5:51pm UTC](https://forum.kirupa.com/t/onenterframe-means-no-sound-for-you/235644 "2007-08-13T17:51:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANEWIDEACo](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@ANEWIDEACo](https://forum.kirupa.com/u/ANEWIDEACo)\
**Post date:** [August 13, 2007, 5:51pm UTC](https://forum.kirupa.com/t/onenterframe-means-no-sound-for-you/235644/1 "2007-08-13T17:51:29Z")

</div>

So I’ve got this script:

[AS]stop();  
// initiate sound  
music = new Sound();  
music.attachSound(“backsound”);  
music.start(0, 999999);  
// set the volume of the sound to zero  
music.setVolume(0);  
// set a variable named ‘vol’  
vol = 0;  
// set another variable named ‘fade’, putting a setinterval function in it  
fade = setInterval(fadeIn, 100);  
// set the initial fade in function  
function fadeIn() {  
// fade the sound in with an increment of 3 in the variable ‘vol’  
vol += 3;  
music.setVolume(vol);  
// put an if condition to restrict the increment in volume after it reaches to 100  
if (vol\>=100) {  
clearInterval(fade);  
// create the ‘step’ variable  
step = 1;  
// create the ‘fade’ variable  
Fade = 0;  
}  
}  
// create the fade in and out function  
// function executed on onEnterFrame  
\_root.onEnterFrame = function() {  
// set fade out  
if (Fade == 1) {  
vol = vol-step;  
if (vol\<0) {  
vol = 0;  
}  
music.setVolume(vol);  
// set fade in  
} else {  
vol = vol+step;  
if (vol\>100) {  
vol = 100;  
}  
music.setVolume(vol);  
}  
};  
[/AS]

…and it works great when I don’t use onEnterFrame, but then shortly after it goes crazy and rips my speakers to shreds. So I need onEnterFrame to prevent that and to keep my button working. Sadly onEnterFrame makes the whole script not work ☹

What do I do?

Thanks in Advance! 😃
