|
-
Senior Member
How to use setTint() -- How to change tint with AS3 -- Informational
I needed help on this but never found anything so I figured it out myself.
Reason I post this is to help anyone else that may need to get this figured out.
Anyway, here it is, how to change tint with a function in AS3:
function tintColor(mc:Sprite, colorNum:Number, alphaSet:Number):void {
var cTint:Color = new Color();
cTint.setTint(colorNum, alphaSet);
mc.transform.colorTransform = cTint;
}
tintColor(sprite1, 0xff0000, .6);
You can also set the mc data type to MovieClip to allow the function to work on movie clips.
If you have any comments and or questions, please feel free to add on to this post.
-
So does this tinting make the image "a little bit more ____ colored" or "grayscale except instead of black it's _____ colored"?
Uh, maybe pictures would be better.

Original.
Tinting "more this color" version.
Tinting "monochromoatic" version.
-
So does this tinting make the image "a little bit more ____ colored" or "grayscale except instead of black it's _____ colored"?
Uh, maybe pictures would be better.

Original.
Tinting "more this color" version. (Blue)
Tinting "monochromatic" version.
Last edited by Shokushu; 04-18-2008 at 01:26 PM.
-
Senior Member
This will set something similar to your middle image.
Just adds a tint color to your MC or Sprite.
similar to using the Tint from the property inspector.
-
Senior Member
Forgot to mention this though:
you must import some classes to get this to work:
import fl.motion.Color;
import flash.geom.ColorTransform;
Example:
import fl.motion.Color;
import flash.geom.ColorTransform;
function tintColor(mc:Sprite, colorNum:Number, alphaSet:Number):void {
var cTint:Color = new Color();
cTint.setTint(colorNum, alphaSet);
mc.transform.colorTransform = cTint;
}
//set mc name, then the color to tint to, and then the alpha value at which to set that color
tintColor(mc2, 0x0000FF, .6);
-
Senior Member
This thing won't allow me to upload files for some reason. Says my quota is exceeded.
But anyway, if you need an example, feel free to email me for it:
[email protected]
-
Looks good. I've always wondered how to change the tint in AS3. Thx!
-
Hi,
thnx a lot for this code . Saved me a lot of time figuring in out for myself .
Didn't know a thing about tinting with actionscripting.
Grtz
-
Senior Member
No Problem, glad to help.
-
-
Senior Member
No Problem, glad to help.
-
Hey, thanks for figuring the code out and sharing it with the community, here's a class i made with it.
Code:
package
{
import flash.display.MovieClip;
import fl.motion.Color;
import flash.geom.ColorTransform;
public class TintColor extends MovieClip
{
private static var _tintColor:Color;
private static var _target:MovieClip;
private static var _colorCode:uint;
private static var _alphaValue:Number;
public function TintColor ():void
{
// leave empty
}
public static function addTint (param1:MovieClip, param2:uint, param3:Number):void
{
_target = param1;
_colorCode = param2;
_alphaValue = param3;
_tintColor = new Color();
_tintColor.setTint (_colorCode, _alphaValue);
_target.transform.colorTransform = _tintColor;
}
}
}
Formated with Pastie : TintClass
-
Btw, the syntax to use the class is :
Code:
TintColor.addTint (TARGET, COLORCODE( ex. 0xFFFFFF ), ALPHAVALUE);
after you imported it of course.
-
Senior Member
Sweet. Thanks for the class, and glad I could provide help.
-
muchas gracias
-
Senior Member
-
This might be a little late, but in the TintColor class, you are extending a MovieClip but in no way do you truly extend a movieclip, you are just extending randomness and modifying the original movieclip. Your TintColor could extend String for all it matters. Kind of doesn't deserve to be its own class that way - could just be a function... but if you want to make it more useful, do something like:
Code:
package
{
import flash.display.MovieClip;
import fl.motion.Color;
import flash.geom.ColorTransform;
public class ExtendedMovieClip extends MovieClip
{
private static var _tintColor:Color;
public function ExtendedMovieClip ():void
{
// leave empty
}
public function addTint (_colorCode:uint, _alphaValue:Number):void {
_tintColor = new Color();
_tintColor.setTint (_colorCode, _alphaValue);
this.transform.colorTransform = _tintColor;
}
}
}
then use like:
Code:
var mc_extended:ExtendedMovieClip = new ExtendedMovieClip();
mc_extended.addTint(0x123456,0.8);
and now you also leave yourself lots of room to add more instance methods (instead of statics) on a movie clip (i.e. addAlpha) AND you've TRULY extended a MovieClip, so your original movieclip methods are all still available to mc_extended now.
That's probably somewhat psuedo-coded, just kind of threw it together, but that's my 2 cents!
Last edited by jenjenut233; 12-10-2008 at 07:00 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|