Nav links don't work

Can anyone tell me why my nav links aren’t working?
I have 28 in total and they work fine when I use,


mcNavBtn1.onRelease = function() {
mcCheck1.gotoAndStop("on");
};

but, I don’t want to have to paste the code 28 times, so I’m trying this,


for(var i:Number = 1; i<29; i++) {
mcNavBtn*.onRelease = function() {
mcCheck*.gotoAndStop("on");
};
}

trace(mcNavBtn*); //comes back as undefined
I’ve also tried the following, which seems to be closer to working,


var btnArray:Array = new Array();
var checkArray:Array = new Array();
for(var i:Number = 1; i<29; i++) {
btnArray* = "mcNavBtn"+i;
checkArray* = "mcCheck"+i;
 
trace(btnArray*);
 
btnArray*.onRelease = function() {
checkArray*.gotoAndStop("on");
};
}

I still haven’t found a solution after 3 nights. Allow me to ask the question in simpler terms.

I have the following code,


mcNavBtn1.onRelease = function() { 
mcCheck1.gotoAndStop("on"); 
}; 
mcNavBtn2.onRelease = function() { 
mcCheck2.gotoAndStop("on"); 
}; 
mcNavBtn3.onRelease = function() { 
mcCheck3.gotoAndStop("on"); 
}; 
mcNavBtn4.onRelease = function() { 
mcCheck4.gotoAndStop("on"); 
}; 
mcNavBtn5.onRelease = function() { 
mcCheck5.gotoAndStop("on"); 
}; 

in such sequence 27 times!
Could someone please tell me of a shorter way to write that?

For loops all the way :wink:


for(var i=1;i<=28;i++){
var mc = this["mcNavBtn"+i];
mc.id = i;
mc.onRelease = function(){
this._parent["mcCheck"+this.id].gotoAndStop("on");
}
}

Supposing that the mcCheck movieclips are located next to the buttons in the hierarchy, not inside the buttons … change the path to fit your needs.