I’m using some code that tweens menu text color on rollover. This basic code works, but I’d like to tighten things up and create a single function that is called on rollover and rollout. The code that needs help is below - create a dynamic textfield and convert it to a movie clip called “textfield_mc”.
var default_color:Number = 0x939672;
var rollover_color:Number = 0xc6c3ab;
var selected_color:Number = 0x63481d;
//
textfield_mc.col = new Color(textfield_mc);
//Initial color
textfield_mc.col.setRGB(default_color);
//
textfield_mc.onRollOver = function() {
changeColor(default_color,rollover_color);
};
textfield_mc.onRollOut = function() {
changeColor(rollover_color,default_color);
};
changeColor = function(defaultColor, targetCol) {
//Get the current color
textfield_mc.col.setRGB(defaultColor);
this.onEnterFrame = function() {
var oR = this.col.getRGB() >> 16;
var oG = this.col.getRGB() >> 8 & 0xFF;
var oB = this.col.getRGB() & 0xFF;
//
var tR = this.targetCol >> 16;
var tG = this.targetCol >> 8 & 0xFF;
var tB = this.targetCol & 0xFF;
//
var dR = tR-oR;
var dG = tG-oG;
var dB = tB-oB;
//
var vR = dR*0.05;
var vG = dG*0.05;
var vB = dB*0.05;
//
this.col.setRGB((oR+vR) << 16 | (oG+vG) << 8 | (oB+vB));
//
};
};
I’m attaching the version that works fine but the code needs to be made for compact.