MovieClip saturation Tweening using ColorMatrix and Tweener
March 13, 2008 — flaim
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






March 19, 2008 at 11:55 pm
This is EXACTLY the kind of example I was looking for today! You’re awesome, thanks for sharing this!
March 31, 2008 at 8:39 pm
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”});
}
March 31, 2008 at 9:42 pm
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
April 8, 2008 at 2:45 pm
Thanks so much!
The code works fantastic and is very
intelligently laid out, easily modifiable too.
Thank you for sharing
Jake
April 8, 2008 at 3:54 pm
Thanks for commenting Jake
always glad when someone has use of my code
Flaim
May 20, 2008 at 8:39 am
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.
May 20, 2008 at 9:04 am
Thanks for sharing!
June 13, 2008 at 12:48 pm
Thanks for sharing ! It was exactelly wha tI was searching for !