# Tween Color on Rollover

**URL:** https://forum.kirupa.com/t/tween-color-on-rollover/216553
**Category:** flash
**Created:** [February 18, 2007, 1:23am UTC](https://forum.kirupa.com/t/tween-color-on-rollover/216553 "2007-02-18T01:23:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Pherank](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@Pherank](https://forum.kirupa.com/u/Pherank)
#### Post date: [February 18, 2007, 1:23am UTC](https://forum.kirupa.com/t/tween-color-on-rollover/216553/1 "2007-02-18T01:23:58Z")

</div>

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”.

```auto

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.
