Button trouble

Hello. Before i ask my question i would really like to say that this is a great place to learn new things and exchange ideas with great people. I really apreciate the effort that goes in keeping this place going.

now to the question…

I have a map of a town with a button for every block in the town. there are about 150 buttons in all. the have the sabe behaviour when you hover over them(they turn green and display a comment)

I got the file from a friend and he chose to ahnd code each button this way…


_root.asanorte.quadras200n.mc202n.btn202n.onRollOver = function () {
       mostracaption (" 202 norte ");
       _root.asanorte.quadras200n.mc202n.gotoAndStop(2);
       }
_root.asanorte.quadras200n.mc202n.btn202n.onRollOut = function () {
       escondecaption ();
       _root.asanorte.quadras200n.mc202n.gotoAndStop(1);
       }

_root.asanorte.quadras200n.mc203n.btn203n.onRollOver = function () {
       _root.asanorte.quadras200n.mc203n.gotoAndStop(2);
       mostracaption (" 203 norte ");
       }
_root.asanorte.quadras200n.mc203n.btn203n.onRollOut = function () {
       _root.asanorte.quadras200n.mc203n.gotoAndStop(1);
       escondecaption ();
       }

_root.asanorte.quadras200n.mc204n.btn204n.onRollOver = function () {
       _root.asanorte.quadras200n.mc204n.gotoAndStop(2);
       mostracaption (" 204 norte ");
       }
_root.asanorte.quadras200n.mc204n.btn204n.onRollOut = function () {
       _root.asanorte.quadras200n.mc204n.gotoAndStop(1);
       escondecaption ();
       }
....... 
.......
.......
it goes on like this for the rest of the buttons

I saw that this is not very practical so I did the following to reduce the code


var squad:Number;
var quad:Number;

for(squad=100; squad <=700; squad+=100){
    //trace("Quadra "+ squad + " norte");
    
    for(quad=2; quad <=16; quad++){
        var msgLabel:Array;
        msgLabel = [((squad+quad)+" norte")];
        //trace(msgLabel);
        //trace("asanorte.quadras"+squad+"n.mc"+(squad+quad)+"n.btn"+(squad+quad)+"n");
        //asaNorte
        _root["asanorte"]["quadras"+squad+"n"]["mc"+(squad+quad)+"n"]["btn"+(squad+quad)+"n"].onRollOver = function () {
            mostracaption (msgLabel);
            _root["asanorte"]["quadras"+squad+"n"]["mc"+(squad+quad)+"n"]["btn"+(squad+quad)+"n"].gotoAndStop(2);
            trace("colorChange");
            };//endRollOver
            
        _root["asanorte"]["quadras"+squad+"n"]["mc"+(squad+quad)+"n"]["btn"+(squad+quad)+"n"].onRollOut = function () {
            escondecaption ();
            _root["asanorte"]["quadras"+squad+"n"]["mc"+(squad+quad)+"n"]["btn"+(squad+quad)+"n"].gotoAndStop(1);
            };//endRollOver
            
        //asaSul
        _root["asasul"]["quadras"+squad+"s"]["mc"+(squad+quad)+"s"]["btn"+(squad+quad)+"s"].onRollOver = function () {
            mostracaption (msgLabel);
            _root["asasul"]["quadras"+squad+"s"]["mc"+(squad+quad)+"s"]["btn"+(squad+quad)+"s"].gotoAndStop(2);
            };//endRollOver
            
        _root["asasul"]["quadras"+squad+"s"]["mc"+(squad+quad)+"s"]["btn"+(squad+quad)+"s"].onRollOut = function () {
            escondecaption ();
            _root["asasul"]["quadras"+squad+"s"]["mc"+(squad+quad)+"s"]["btn"+(squad+quad)+"s"].gotoAndStop(1);
            };//endRollOver
    };//endFor
};//endFor

the result is that the labels appear but i can’t seem to get the gotoAndStop() to work
I tried doing it with a with(){} statemente but had no luck onRollover and onRollOut did not work.

any ideas on how this can be implemented in a better way?
thanks in advance :slight_smile: