Image Color Tinting using Actionscript
Description: Change the tint of an image using the ColorTransform and Transform classes
Author: John Bezanis
Added: April 11th 2008
Version: Flash 8
Flash 8 makes tinting an image a piece of cake with the ColorTransform and Transform classes. The above demo uses a few lines of code on a movie clip to create a color shifting effect.
Begin by importing an image to the stage using File->Import To Stage.
Convert it to a movie clip by right clicking the image and clicking Convert to Symbol. Set the type to Movie Clip.
Select the movie clip by single clicking it and insert the following code into the actions tab:
- onClipEvent(load){
- //Import the classes needed to transform the color
- import flash.geom.ColorTransform;
- import flash.geom.Transform;
- //A starting amount to tint the image
- redamount = 0;
- //Is the image getting more red or more blue?
- goingred = true;
- }
- //Run at the start of each frame
- onClipEvent(enterFrame) {
- //if going red is set to true, set the color transform to tint the image more red
- if (goingred) {
- redamount++;
- //otherwise, it is getting more blue
- } else {
- redamount--;
- }
- //the boundaries. If a limit (0 or 64) has been reached, flip from going red to going blue
- if (redamount == 0 || redamount == 64) {
- goingred = !goingred;
- }
- //Declare a new ColorTransform object
- var colorTrans:ColorTransform = new ColorTransform();
- //Set the red offset to the specified amount. Higher is stronger
- colorTrans.redOffset = redamount;
- //when the red offset is low, the blue offset is high, and vice versa.
- colorTrans.blueOffset = 64-redamount;
- //Create a new Transform object. This is attached to the movieclip 'tintedimage'
- var trans:Transform = new Transform(this);
- //apply the color transform to the transform object
- trans.colorTransform = colorTrans;
- }
The source file is available below for download:
Download Source File
Download Demo SWF
Comments
awesome post, thanks for the help!
April 18th 2008 10:04AM - isaac
muy bueno gracias me esta sirviendo de mucho =D
May 23rd 2008 10:05AM - derleth
Found the Color class today - it extends ColorTransform, so can be applied to any DisplayObject in the same way as ColorTransform, but adds tinting functionality so it's a load easier to get your head around instead of the offsets and multipliers :)
var c:Color = new Color();
c.setTint( Math.random()*0xFFFFFF,.4 );
mySprite.transform.colorTransform = c;
var c:Color = new Color();
c.setTint( Math.random()*0xFFFFFF,.4 );
mySprite.transform.colorTransform = c;
June 4th 2008 06:06AM - tripleaxis
The Color class extends Object, as does ColorTransform, but Color is deprecated.
June 4th 2008 08:06AM - John
How easily could you add this effect to a scroller bar? Basically it would be great to be able to let the user scroll (Say with 3 RGB scrollers) giving the amount of tint they want then let them save a copy of the image with the tint they wanted?
April 15th 2009 04:04PM - Mansafe
i want asfile format
June 5th 2009 05:06AM - adfdf
after i've convert the symbol..
the script was error..
what should I do?
the script was error..
what should I do?
July 24th 2009 05:07AM - sulieya
I love this script! I've used it and it totally rocks.
September 9th 2009 09:09PM - emouse
great
November 6th 2009 09:11AM - vigrx
powerful
November 6th 2009 10:11AM - vigrx
The sort is usually dated of a awareness house that has a own campaign to it and most bathrobe locations have the tape thrift character or weblog on the point."
November 27th 2009 10:11PM - MBA admission essay
Excellent post.I want to thank you for this informative read, I really appreciate sharing this great post.
November 27th 2009 10:11PM - Thesis Example
Thanks for giving us this great code.
December 9th 2009 07:12PM - wealthy affiliate
That is an awesome cube, thanks for sharing.
December 13th 2009 07:12AM - dental
Oh Wow!!!!! thank
December 18th 2009 08:12AM - download mp3
WOW! Great Info. Thanks for sharing.
December 26th 2009 06:12AM - QBasic
I love this script! I've used it and it totally rocks.
January 1st 2010 09:01PM - Cialis
Image color tinting on flash8 easier than java applet but quality of color is same.
January 4th 2010 03:01AM - jobs
That is an awesome cube, thanks for sharing.
January 5th 2010 03:01PM - watch invictus online
I love this script! I've used it and it totally rocks.
January 5th 2010 03:01PM - watch the lovely bones
Image color tinting on flash8 easier than java applet but quality of color is same
January 5th 2010 03:01PM - watch a single man online
I agree with you, but it's subjectivism.
January 17th 2010 05:01AM - download icons
Thank you for sharing this useful information.
January 18th 2010 10:01PM - film
I amazed in image color tinting using actionscript. It's great feature.
January 18th 2010 10:01PM - book
Good stuff to know :)
January 19th 2010 08:01AM - Ares
thanks for the tutorial. it'll come in handy for developing some new flash stuff for my bondage site.
January 19th 2010 02:01PM - bondage
I like how the images changes colors. It makes the city look alive.
January 20th 2010 08:01PM - Store Supplies
good code. i used it. thanks
January 21st 2010 01:01PM - colorful images
Echoing the previous comments, this is by far the best quickstart I
January 23rd 2010 06:01AM - Clasamente
Well worth the read. Thanks for sharing this information. I got a chance to know about this.
January 23rd 2010 06:01AM - Statistici Fotbal
Image Color Tinting using Actionscript
January 24th 2010 10:01AM - Ares 8
That is awesome. I love action script and doing image editing. It was hard for me to learn how to use Photo shop but I think I understand this.
January 24th 2010 03:01PM - Cheap Auto Insurance
Action script is really an awesome program. It took me a good while to get the hang of it. Thanks
January 26th 2010 01:01PM - Sarasota marketing
Special thank for good post.
February 5th 2010 09:02PM - โหลดเพลงà
Thank for the information
February 6th 2010 07:02AM - โหลดเพลงm
Special thank for good post.
February 10th 2010 04:02AM - โหลดเพลงà
Special thank for good post.
February 10th 2010 08:02AM - โหลดเพลงà
Add a Comment





