# AS Color tween & ColorTransform Object

**URL:** <https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707>\
**Category:** flash\
**Created:** [April 15, 2006, 6:23pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707 "2006-04-15T18:23:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 6:23pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/1 "2006-04-15T18:23:49Z")

</div>

Hello,

I found this old thread and tried using both codes to color tween. I could not get either work. I know its probably very simple but I am very new to flash. I have attached the .fla. If anyone can get both example of the color tweens to work so I can understand how these function better would help greatly.

Also I would like to hear pros and cons on wither method.

[http://www.kirupa.com/forum/showthread.php?t=210435](http://www.kirupa.com/forum/showthread.php?t=210435)

Thank you

```auto
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
import flash.geom.Transform;
for (var i = 0; i < 1; i++) {
 var yb:Button = (this.attachMovie ("yelBox", "yelBox", +i, i));
 this._x = 275;
 this._y = 200;
 this._xscale = 50;
 this._yscale = 25;
}
for (var i = 0; i < 1; i++) {
 yb.onRelease = function () {
  var currentx:Number = this._x;
  new Tween (this, "_width", Back.easeInOut, 100, 200, 2, true);
  //colorTween
  var colour:Color = new Color (myMC);
  colour.setRGB (0xFFFFFF);
  var trans:Object = colour.getTransform ();
  var rb:Tween = new Tween (this, "rb", Strong.easeOut, trans.rb, Math.random () * 0xFF, 3, true);
  var gb:Tween = new Tween (this, "gb", Strong.easeOut, trans.gb, Math.random () * 0xFF, 3, true);
  var bb:Tween = new Tween (this, "bb", Strong.easeOut, trans.bb, Math.random () * 0xFF, 3, true);
  rb.onMotionChanged = function ():Void {
   colour.setTransform (trans);
  };
 };
}
//color transform object starts here
/*import flash.geom.ColorTransform;
import flash.geom.Transform;
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
var colorTrans:ColorTransform = new ColorTransform();
colorTrans.rgb = 0xFFFFFF;
var trans:Transform = new Transform(my_mc);
this.onMouseDown = function() {
    colorTween(my_mc, colorTrans, trans, 1, 0x00, 0xFF, 0x80, 0x00, Strong.easeOut);
};
//
function colorTween(mc:MovieClip, ct:ColorTransform, t:Transform, seconds:Number, a:Number, r:Number, g:Number, b:Number, ease:Function):Void {
    var alphaTween:Tween = new Tween(ct, "alphaOffset", ease, ct.alphaOffset, a, seconds, true);
    var redTween:Tween = new Tween(ct, "redOffset", ease, ct.redOffset, r, seconds, true);
    var greenTween:Tween = new Tween(ct, "greenOffset", ease, ct.greenOffset, g, seconds, true);
    var blueTween:Tween = new Tween(ct, "blueOffset", ease, ct.blueOffset, b, seconds, true);
    greenTween.onMotionChanged = function() {
        t.colorTransform = ct;
    };
    greenTween.onMotionFinished = function() {
        trace(mc._name + " is now 0x" + colorTrans.rgb.toString(16));
    };
}*/

```

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 15, 2006, 7:12pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/2 "2006-04-15T19:12:24Z")

</div>

The two different methods are pretty much exactly the same except that devonair’s script uses Flash 8’s ColorTransform object whereas mine uses the deprecated Color object.

```auto
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.geom.ColorTransform;
import mx.utils.Delegate;
var yb:Button = this.attachMovie("yelBox", "yelBox", +i, i);
yb._x = 275;
yb._y = 200;
yb._xscale = 50;
yb._yscale = 25;
yb.onRelease = function() {
 //colorTween
 var c:ColorTransform = this.transform.colorTransform;
 var rb:Tween = new Tween(c, "redOffset", Strong.easeOut, c.redOffset, Math.random() * 0xFF, 3, true);
 var gb:Tween = new Tween(c, "greenOffset", Strong.easeOut, c.greenOffset, Math.random() * 0xFF, 3, true);
 var bb:Tween = new Tween(c, "blueOffset", Strong.easeOut, c.blueOffset, Math.random() * 0xFF, 3, true);
 rb.onMotionChanged = Delegate.create(this, function ():Void {
  this.transform.colorTransform = c;
 });
};

```

:hoser:

---

<div class="post-metadata">

**Author:** ![BrAnDX105](https://avatars.discourse-cdn.com/v4/letter/b/85e7bf/32.png) [@BrAnDX105](https://forum.kirupa.com/u/BrAnDX105)\
**Post date:** [April 15, 2006, 7:27pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/3 "2006-04-15T19:27:54Z")

</div>

Would you be able to explain this block of code:

```auto
  
rb.onMotionChanged = Delegate.create(this, function ():Void {
                this.transform.colorTransform = c;
   });

```

I’m don’t even really need the code for anything, I’m just trying to understand what it means :elderly:

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 15, 2006, 7:42pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/4 "2006-04-15T19:42:14Z")

</div>

> [@BrAnDX105](#):
>
> Would you be able to explain this block of code:
> 
> ```auto
>   
> rb.onMotionChanged = Delegate.create(this, function ():Void {
> this.transform.colorTransform = c;
> });
> 
> ```
> 
> I’m don’t even really need the code for anything, I’m just trying to understand what it means :elderly:

Delegate is a class in the mx.utils package. It creates the function in the scope of another object using Function.apply. In this example without delegating the function it will run in the scope of _rb_ (the Tween). By using Delegate we can execute it in the scope of _this_ (the movie clip _yb_) so we can easily reference its _transform_ property. You can find more info in the Component Language Reference in the Help File. Hope this helps :hoser:

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 7:46pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/5 "2006-04-15T19:46:11Z")

</div>

> 

TheCanadian]The two different methods are pretty much exactly the same except that devonair’s script uses Flash 8’s ColorTransform object whereas mine uses the deprecated Color object.

Any pros and cons?

Thanks for the code.

---

<div class="post-metadata">

**Author:** ![BrAnDX105](https://avatars.discourse-cdn.com/v4/letter/b/85e7bf/32.png) [@BrAnDX105](https://forum.kirupa.com/u/BrAnDX105)\
**Post date:** [April 15, 2006, 7:46pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/6 "2006-04-15T19:46:25Z")

</div>

> [@TheCanadian](#):
>
> Delegate is a class in the mx.utils package. It creates the function in the scope of another object using Function.apply. In this example without delegating the function it will run in the scope of _rb_ (the Tween). By using Delegate we can execute it in the scope of _this_ (the movie clip _yb_) so we can easily reference its _transform_ property. You can find more info in the Component Language Reference in the Help File. Hope this helps :hoser:

Yep, it does! I wasn’t even aware the class existed. I guess I should read through the help files more to find out about these things. Thanks a lot for the help :toad:

---

<div class="post-metadata">

**Author:** ![TheCanadian](https://avatars.discourse-cdn.com/v4/letter/t/67e7ee/32.png) [@TheCanadian](https://forum.kirupa.com/u/TheCanadian)\
**Post date:** [April 15, 2006, 10:34pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/7 "2006-04-15T22:34:11Z")

</div>

> [@artistwantab](#):
>
> Any pros and cons?
> 
> Thanks for the code.

Not really - if you’re using Flash 8, use the ColorTransform class :cowboy:

---

<div class="post-metadata">

**Author:** ![artistwantab](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@artistwantab](https://forum.kirupa.com/u/artistwantab)\
**Post date:** [April 15, 2006, 10:47pm UTC](https://forum.kirupa.com/t/as-color-tween-colortransform-object/185707/8 "2006-04-15T22:47:51Z")

</div>

> [@TheCanadian](#):
>
> Not really - if you’re using Flash 8, use the ColorTransform class :cowboy:

I am using F8.  
I just wanted to make sure there wasn’t any other issues I should know about in advance.
