MovieClip saturation Tweening using ColorMatrix and Tweener

saturation tweening

Here is a more complicated implementation of ColorMatrix Class in conjunction with Tweener in order to get a “_saturation” property of a MovieClip which can then be fully controlled by Tweener (used in this example) - or other Tweening engines.

Here is the sample code (you can download FLA example HERE):

import ColorMatrix;
import caurina.transitions.Tweener;
import flash.filters.ColorMatrixFilter;

MovieClip.prototype.addProperty(”_saturation”, this.getSAT, this.setSAT);
MovieClip.prototype.setSAT = function(sth)
{
 this._saturation = sth;
};
MovieClip.prototype.getSAT = function()
{
 return this._saturation;
};

example_mc._saturation=0;
example_mc.cm = new ColorMatrix();
example_mc.cm.adjustSaturation(example_mc._saturation-100);
example_mc.filters = [new ColorMatrixFilter(example_mc.cm)];

changeSAT = function(what)
{
 //the same as above but in form of a function executed on each Tweener UPDATE (onUpdate :)
 what.cm = new ColorMatrix();
 what.cm.adjustSaturation(what._saturation-100);
 what.filters = [new ColorMatrixFilter(what.cm)];
};

// ___________________USAGE

example_mc.onRollOver = function()
{
 Tweener.addTween(this,{_saturation:100,time:.4,transition:”easeOutSine”,onUpdate:changeSAT,onUpdateParams:[this]});
};
example_mc.onRollOut = function()
{
 Tweener.addTween(this,{_saturation:0,time:.4,transition:”easeOutSine”,onUpdate:changeSAT,onUpdateParams:[this]});
};

the full code available for download is fully commented - here

 FLAIM

8 Responses to “MovieClip saturation Tweening using ColorMatrix and Tweener”

  1. JS Says:

    This is EXACTLY the kind of example I was looking for today! You’re awesome, thanks for sharing this! :-)

  2. olivier Says:

    Hi, i nice piece of code but i try to adapt it to as3 with a blur FX , but it doesnt work :(

    Do you have an example in as3?
    I tried using the registerSpecialProperty property but doesn’t work :

    import caurina.transitions.Tweener;
    import flash.filters.BlurFilter;

    Tweener.registerSpecialProperty(”_blurx”, blurx_get, blurx_set, [BlurFilter, "blurX"]);
    function blurx_get(p_obj:Object, p_parameters:Array):Number
    {
    return p_parameters[0][p_parameters[1]];
    }
    function blurx_set(p_obj:Object, p_value:Number, p_parameters:Array):void
    {
    p_parameters[0][p_parameters[1]] = p_value;
    }
    mc.addEventListener(MouseEvent.MOUSE_OVER, up);
    mc.addEventListener(MouseEvent.MOUSE_OUT, down);

    function up(e:MouseEvent):void
    {
    Tweener.addTween(this, {_blurx:20, time:3, transition:”easeOutQuad”});
    }

    function down(e:MouseEvent):void
    {
    Tweener.addTween(this, {_blurx:0, time:3, transition:”easeOutQuad”});
    }

  3. flaim Says:

    Hey Olivier,

    I’ve done this with Tweener in AS3 using something like that:

    Tweener.addTween(my_mc, {_blur_blurX:15, time:1});

    it works even if you don’t instantiate a new blur filter and add it to .filters Array of a MC… Tweener should add the filter automatically…

    I’ll check this tomorrow and post something about it too because I haven’t seen anything about tweening blurx and y using as3 on the net :)
    cheers,

    FLAIM

  4. Jake S. Says:

    Thanks so much!

    The code works fantastic and is very
    intelligently laid out, easily modifiable too.

    Thank you for sharing :)

    Jake

  5. flaim Says:

    Thanks for commenting Jake :) always glad when someone has use of my code ;)

    Flaim

  6. Terry Corbet Says:

    Did the question concerning an AS3 example get answered off line? I would really, really appreciate a simple AS3-only file to just test with the free command-line SDK.

    Thank you.

  7. Cris Says:

    Thanks for sharing!

  8. JP Says:

    Thanks for sharing ! It was exactelly wha tI was searching for !

Leave a Reply