Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Creating Interaction with ActionScript > Creating interactivity and visual effects > Setting color values | |||
You can use the methods of the built-in ColorTransform class (flash.geom.ColorTransform) to adjust the color of a movie clip. The rgb property of the ColorTransform class assigns hexadecimal red, green, blue (RGB) values to the movie clip. The following example uses rgb to change an object's color, based on which button the user clicks.
To set the color value of a movie clip:red_btn, green_btn, blue_btn, and black_btn. import flash.geom.ColorTransform; import flash.geom.Transform; var colorTrans:ColorTransform = new ColorTransform(); var trans:Transform = new Transform(car_mc); trans.colorTransform = colorTrans;
car_mc movie clip to blue, add the following code to the Actions panel:
blue_btn.onRelease = function() {
colorTrans.rgb = 0x333399; // blue
trans.colorTransform = colorTrans;
};
The preceding snippet of code changes the rgb property of the color transform object and reapplies the color tranform effect to the car_mc movie clip whenever the button is pressed.
red_btn, green_btn, and black_btn) to change the color of the movie clip to the corresponding color.
Your code should now look like the following example (new code is in bold):
import flash.geom.ColorTransform;
import flash.geom.Transform;
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
trans.colorTransform = colorTrans;
blue_btn.onRelease = function() {
colorTrans.rgb = 0x333399; // blue
trans.colorTransform = colorTrans;
};
red_btn.onRelease = function() {
colorTrans.rgb = 0xFF0000; // red
trans.colorTransform = colorTrans;
};
green_btn.onRelease = function() {
colorTrans.rgb = 0x006600; // green
trans.colorTransform = colorTrans;
};
black_btn.onRelease = function() {
colorTrans.rgb = 0x000000; // black
trans.colorTransform = colorTrans;
};
For more information about the methods of the ColorTransform class, see ColorTransform (flash.geom.ColorTransform) in the ActionScript 2.0 Language Reference.
|
|
|
|