# Updating as2 function

**URL:** <https://forum.kirupa.com/t/updating-as2-function/306432>\
**Category:** Uncategorized\
**Created:** [March 15, 2010, 1:43pm UTC](https://forum.kirupa.com/t/updating-as2-function/306432 "2010-03-15T13:43:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Navarone](https://avatars.discourse-cdn.com/v4/letter/n/f9ae1b/32.png) [@Navarone](https://forum.kirupa.com/u/Navarone)\
**Post date:** [March 15, 2010, 1:43pm UTC](https://forum.kirupa.com/t/updating-as2-function/306432/1 "2010-03-15T13:43:07Z")

</div>

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?

```auto

// 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;
            }
        }
    };
}

```
