You can use the methods of the built-in Color object to adjust the color of a movie clip. The setRGB
method assigns hexadecimal RGB (red, green, blue) values to the object. The following example uses setRGB
to change an object's color based on user input.
To set the color value of a movie clip:
carColor
as the instance name.color chip
, place four instances of the button on the Stage, and name them red
, green
, blue
, and black
. new Color
, and choose _root.carColor
for the target. Enter myColor =
in the Expression text box. Your code should look like this:
myColor = new Color(_root.carColor);
onRelease
. Enter the button instance nameeither _root.red
, _root.green
, _root.blue
, or _root.black
in the Object text box.setRGB
. Enter the Color object name myColor
in the Object text box. Enter the hexadecimal representation for the color in the Parameter text box:
Color | Hexadecimal value |
---|---|
Red | 0xff0000 |
Green | 0x00ff00 |
Blue | 0x0000ff |
Black | 0x000000 |
myColor = new Color(_root.carColor) _root.blue.onRelease = function(){ myColor.setRGB(0x0000ff) } _root.red.onRelease = function(){ myColor.setRGB(0xff0000) } _root.green.onRelease = function(){ myColor.setRGB(0x00ff00) } _root.black.onRelease = function(){ myColor.setRGB(0x000000) }
For more information about the methods of the Color object, see Color object.