[AS2] Active/viewed button-related problems

Having spent ages finally getting an active/viewed button script to work, I thought all I had to do to complete things was add the button actions (I want each button to load an external swf). For some reason, this is then preventing the above working as it should. I suspect it’s obvious to someone who understands this stuff, but I’ve got things working so far through a mixture of copy/paste and trial&error, and I’ve got completely stuck at this last hurdle. If anyone could help I’d be seriously grateful!

My main button script is as follows:


for(i=1; i<=4; i++){
//    change the above number depending on the number of buttons;
    this["gal"+i].enabled = true;
    this["gal"+i].onRollOver = over;
    this["gal"+i].onRollOut = out;
    this["gal"+i].onPress = down;
    this["gal"+i].onRelease = up;
}

// active button script //
var galbtns:Array = [gal1, gal2, gal3, gal4];

gal1.onRelease = gal2.onRelease = gal3.onRelease = gal4.onRelease = function(){
    activeGalBtn(this);
}

function activeGalBtn(mc:MovieClip):Void{
    for(var gal_i:Number=0; gal_i<galbtns.length; gal_i++){
        if(galbtns[gal_i]!=mc){
            if (galbtns[gal_i].viewed == true) {
                if (galbtns[gal_i]._currentframe == 7) {
                    // fades out after new button selected
                    galbtns[gal_i].gotoAndPlay("viewed");
                    galbtns[gal_i].enabled=true;
                } else {
                    // otherwise keeps button faded
                    galbtns[gal_i].gotoAndStop("viewedstatic");
                    galbtns[gal_i].enabled=true;
                }
            } else {
                // keeps button in original state if no change
                galbtns[gal_i].gotoAndStop("reset");
                galbtns[gal_i].enabled=true;
            }
        }else{
            // current button selected
            galbtns[gal_i].gotoAndStop("up");
            galbtns[gal_i].enabled=false;
        }
    }
}
// end active button script //

// new button bits //
function over() {
    this.gotoAndPlay("over");
}
function out() {
    if (this.viewed == true) {
        this.gotoAndPlay("viewed");
    } else {
        this.gotoAndPlay("out");
    }
}
function down() {
    this.gotoAndStop("down");
}
function up() {
    viewed = true;
    this.gotoAndStop("up");
}
// end new button bits //

I’m using 4 buttons at the moment but hope to have 30 or so when I finally get things working, hence the need for a script like this.

Each button is a movie clip with simple text fade-out operations depending on the state (up, over, active, viewed, etc). Using the above code everything is fine, but when I add the following line at the bottom, it’s skipping parts of the above and sticking in the “down” state until I roll off; then it resets itself.


gal1.onRelease = function() {
_root.Container.loadMovie("externalmovie.swf");
};

I think this may have something to do with the order it’s all in, and I suspect having most of the above commands in a for / if loop might not support me adding additional actions afterwards which may overrule the other ones.

Without anyone else wasting too much time, if anyone can see the (presumably obvious to some people) mistake I’m making in the above, please let me know!