views:

631

answers:

1

I have this code that should change the color of a dynamic textfield when I rollover the link movieclip, and then back when I rollout. I get no compiler error, it just doesn't work.

function textColor(mc_function:MovieClip, tf_text:TextField) {
mc_function.onRollOver = function() {
 tf_text.textColor = 0x7cb0b7; 
};
mc_function.onRollOut = function() {
 tf_text.textColor = 0xffffff; 
};
}

boxLink(link_a1,text_a1);
boxLink(link_a2,text_a2);
boxLink(link_a3,text_a3);

Any thoughts?

+1  A: 

Try this:

function SetMouseAction(pMovieClip, pTextField):Void {
    pMovieClip.linkedText = pTextField;
    pMovieClip.onRollOver = function() {
      this.linkedText.textColor = 0x7cb0b7; 
    };
    pMovieClip.onRollOut = function() {
      this.linkedText.textColor = 0xffffff; 
    };
}

SetMouseAction(link_a1, text_a1);
SetMouseAction(link_a2, text_a2);
SetMouseAction(link_a3, text_a3);

at least I have tested it and it works for me

Unreality
Thanks! Is there a way I can simplify the code, like getting rid of the repeating SetMouseAction() ? Something automatic?
mofle
for (var i:Number=1;i<=3;i++) { SetMouseAction(_root["link_a" + i], _root["text_a" + i]);}
Unreality