-
How to color the tint of a movieclip using as3
Hi...
I am trying to figure out how to color the tint of a movieclip using as3.
Using as2 I would do the following :
var clSymbol:Color = new Color(mcSymbol);
clSymbol.setRGB(0xFF0000);
..and the movieclip mcSymbol would turn red.
Very easy using as2 but I don´t know how to do the same thing using as3.
Any idea ?
thx
-
hippie hater
Use the colorTransform object
If you can't explain it simply, you don't understand it well enough.
Albert Einstein
-
Thx,
var colorTransform:ColorTransform = mcSymbol.transform.colorTransform;
colorTransform.color = 0xFF0000;
mcSymbol.transform.colorTransform = colorTransform;
-
Great - I can change the color BUT can I do it with a tween class?
Can I change the tint over time (like alpha) using a tween transition?
-
a tween transition can change any "property", but not objects, and color is an object. So alpha, x, y, width, height, scale, etc...
But you could set up a timer interval that would change the color slowly
Last edited by malihk; 05-11-2007 at 12:49 AM.
-
half as fun, double the price
here is an example using the Tween class with a tint. Assumes a movie clip with the instance name "clip"
Code:
import fl.transitions.*;
import fl.transitions.easing.*;
// function to transition from one colorTransform to another
function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;
}
// start and end colors for tween
var startColor:ColorTransform = new ColorTransform(); // default color, no tint
var endColor:ColorTransform = new ColorTransform();
endColor.color = 0xFF0000; // end color of red
// create tween; use "" for property since no
// property is being tweened; just using the
// Tween class here to handle the animation
// using the values 0 and 1 (0% to 100%)
// over a time period of 50 frames
var tween:Tween = new Tween(clip, "", Strong.easeOut, 0, 1, 50);
// listen for the TweenEvent.MOTION_CHANGE event to
// perform the custom color tween
tween.addEventListener(TweenEvent.MOTION_CHANGE, tweenTransform);
// TweenEvent.MOTION_CHANGE handler using interpolateColor
// to set the colorTransform of clip (tween.obj) based on
// the startColor and endColor properties defined earlier
function tweenTransform(event:TweenEvent):void {
// use tween position for interpolation of
// start and end colors (value 0 - 1)
clip.transform.colorTransform = interpolateColor(startColor, endColor, tween.position);
}
Last edited by senocular; 05-11-2007 at 11:34 AM.
-
good post senocluar! I like how you use the tween class as an interval timer. Good creativity!
-
Thanks!
WOW. That was much more than I expected. I'm not a programmer but I willl try your code and see if I can get it to work in my animation.
Thanks for taking the time to post this.
-
half as fun, double the price
This could also be done with a motion tween and the color option in the Property Inspector if you didnt want to do it in code
-
Yes, but it is for a menu and I really like to keep it in the code so i don't have to jump around in the timeline for each change. Thanks for the suggestion.
-
I'm getting errors when I test the movie -
The class or interface "ColorTransform" cannot be loaded
The class or interface "Tween" cannot be loaded
The class or interface "TweenEvent" cannot be loaded
The only change I made was to change "clip" to the actual name of my movieclip.
Any ideas?
-
half as fun, double the price
-
-
half as fun, double the price
Make sure your publish settings are set for ActionScript 3, not 2.
-
duh. I assumed it would default to that
Thanks
-
Originally Posted by senocular
Make sure your publish settings are set for ActionScript 3, not 2.
What if you are using flash 8 professional? Because I get the same error and I dont think I have actionscript 3. Help
-
Originally Posted by senocular
Make sure your publish settings are set for ActionScript 3, not 2.
What if you are using flash 8 professional? Because I get the same error and I dont think I have actionscript 3. Please Help!!!
-
publish to flash player 9 is supposed to work for as3 compilation ?
I'd like to continue to use f8 professional a while longer..
-
and applyying to a part thereof ?
wondering if i wanted to do this for a part of the bitmap where would I drop the rectangle argument
i tried putting it in the end one but didnt work...
Code:
var endColor:ColorTransform = new ColorTransform(rect,null);
Originally Posted by senocular
here is an example using the Tween class with a tint. Assumes a movie clip with the instance name "clip"
Code:
import fl.transitions.*;
import fl.transitions.easing.*;
// function to transition from one colorTransform to another
function interpolateColor(start:ColorTransform, end:ColorTransform, t:Number):ColorTransform {
var result:ColorTransform = new ColorTransform();
result.redMultiplier = start.redMultiplier + (end.redMultiplier - start.redMultiplier)*t;
result.greenMultiplier = start.greenMultiplier + (end.greenMultiplier - start.greenMultiplier)*t;
result.blueMultiplier = start.blueMultiplier + (end.blueMultiplier - start.blueMultiplier)*t;
result.alphaMultiplier = start.alphaMultiplier + (end.alphaMultiplier - start.alphaMultiplier)*t;
result.redOffset = start.redOffset + (end.redOffset - start.redOffset)*t;
result.greenOffset = start.greenOffset + (end.greenOffset - start.greenOffset)*t;
result.blueOffset = start.blueOffset + (end.blueOffset - start.blueOffset)*t;
result.alphaOffset = start.alphaOffset + (end.alphaOffset - start.alphaOffset)*t;
return result;
}
// start and end colors for tween
var startColor:ColorTransform = new ColorTransform(); // default color, no tint
var endColor:ColorTransform = new ColorTransform();
endColor.color = 0xFF0000; // end color of red
// create tween; use "" for property since no
// property is being tweened; just using the
// Tween class here to handle the animation
// using the values 0 and 1 (0% to 100%)
// over a time period of 50 frames
var tween:Tween = new Tween(clip, "", Strong.easeOut, 0, 1, 50);
// listen for the TweenEvent.MOTION_CHANGE event to
// perform the custom color tween
tween.addEventListener(TweenEvent.MOTION_CHANGE, tweenTransform);
// TweenEvent.MOTION_CHANGE handler using interpolateColor
// to set the colorTransform of clip (tween.obj) based on
// the startColor and endColor properties defined earlier
function tweenTransform(event:TweenEvent):void {
// use tween position for interpolation of
// start and end colors (value 0 - 1)
clip.transform.colorTransform = interpolateColor(startColor, endColor, tween.position);
}
-
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
|