I have a project I did a few years ago in AS2 and maybe a little of AS1. I am learning AS3 and I need to update a sound function to the new AS3 standards. The function allows me to fade a sound object up or down. This function was in the first frame of my movie. Should I make this it’s own class?
// variables for sound object
var bgVol = 0;
// volume increment for every frame
///////////////////////////////////////////////////
// this function fade the background music down or up
function fadeBGAudio(upDown, sndObj) {
this.onEnterFrame = function() {
var bgVolMax = 20;
if (upDown == 1) {
// Fade the audio up
bgVol = bgVol+1;
//trace("test"+bgVol);
if (bgVol<=bgVolMax) {
sndObj.setVolume(bgVol);
} else {
sndObj.setVolume(bgVolMax);
delete this.onEnterFrame;
}
} else if (upDown == 2) {
bgVolMin = 0;
// fade the audi out
bgVol = bgVol-1;
//trace("test"+bgVol);
if (bgVol>=bgVolMin) {
sndObj.setVolume(bgVol);
} else {
sndObj.setVolume(bgVolMin);
delete this.onEnterFrame;
}
} else {
//(UpDown == 0)
// fade the audio down to min value
var bgVolMin = 10;
bgVol = bgVol-1;
//trace("test"+bgVol);
if (bgVol>=bgVolMin) {
sndObj.setVolume(bgVol);
} else {
sndObj.setVolume(bgVolMin);
delete this.onEnterFrame;
}
}
};
}