Rewriting code for main timeline

I’ve got an MC name “bg” with the following code on it:


onClipEvent (load) {
    var a = 15; // this is the speed of the transition, the higher the value, the slower the fade
    myColor = new Color(bg); // this sets up the color object, and sets the other variables to the initial values
    var cRGB = myColor.getRGB();
    var cHEX = cRGB.toString(16);
    var newRGB = cRGB; 
    var newHEX = cHEX;
}
onClipEvent (enterFrame) {
    if (cHEX<>newHEX) {
        // break the hex into 3 values, one for each color
        var cHEX_r = parseInt(cHEX.substring(0, 2), 16);
        var newHEX_r = parseInt(newHEX.substring(0, 2), 16);
        var cHEX_g = parseInt(cHEX.substring(2, 4), 16);
        var newHEX_g = parseInt(newHEX.substring(2, 4), 16);
        var cHEX_b = parseInt(cHEX.substring(4, 6), 16);
        var newHEX_b = parseInt(newHEX.substring(4, 6), 16);
        // adjust each value independantly, so you don't get any wierd colors showing up
        // adjust red value
        if (cHEX_r<>newHEX_r) {
            var r_diff = Math.round((newHEX_r-cHEX_r)/a);
            if (Math.abs(r_diff)<1) {
                cHEX_r = newHEX_r;
            } else {
                cHEX_r += r_diff;
            }
        }
        // then green value
        if (cHEX_g<>newHEX_g) {
            var g_diff = Math.round((newHEX_g-cHEX_g)/a);
            if (Math.abs(g_diff)<1) {
                cHEX_g = newHEX_g;
            } else {
                cHEX_g += g_diff;
            }
        }
        // then blue value
        if (cHEX_b<>newHEX_b) {
            var b_diff = Math.round((newHEX_b-cHEX_b)/a);
            if (Math.abs(b_diff)<1) {
                cHEX_b = newHEX_b;
            } else {
                cHEX_b += b_diff;
            }
        }
        // adjust the color to the new value
        // sets the decimal numbers back to hex
        cHEX_r = cHEX_r.toString(16);
        cHEX_g = cHEX_g.toString(16);
        cHEX_b = cHEX_b.toString(16);
        // this check is needed if there is a 0 value in the string, when you use toString() it will leave 0's blank,
        // instead of filling them in, so you get "0" instead of "00" or "e" instead of "0e" so this fills in the 0
        // if it is needed
        while(cHEX_r.length < 2) {
            cHEX_r = "0"+cHEX_r;
        }
        while(cHEX_g.length < 2) {
            cHEX_g = "0"+cHEX_g;
        }
        while(cHEX_b.length < 2) {
            cHEX_b = "0"+cHEX_b;
        }
        // end toString() fix
        cHEX = cHEX_r+cHEX_g+cHEX_b; // set the current HEX variable
        myColor.setRGB(parseInt(cHEX, 16)); // set the color of the BG (or object)
    }
}

I’ve tried removing the code from the “bg” clip and placing it on the main timeline using this sort of syntax: “bg.onEnterFrame = function() { }” but the code doesn’t execute so there’s obviously something else that needs to be updated for this to work on the timeline. Thanks for the help.