Creating Interaction with ActionScript > Creating complex interactivity > Setting color values |
![]() ![]() ![]() |
Setting color values
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:
1 |
Select a movie clip on the Stage. |
||||||||||
2 |
In the Property inspector, enter |
||||||||||
3 |
Create a button named |
||||||||||
4 |
Select frame 1 in the main Timeline and choose Window > Actions. |
||||||||||
5 |
To create a new Color object, in the Actions toolbox, click the Objects category, then click Movie and Color, double-click |
||||||||||
Your code should look like this: |
|||||||||||
myColor = new Color(_root.carColor); |
|||||||||||
6 |
To associate an event with an object, in the Actions toolbox, click the Objects category, then click Movie, Movie Clip, and Events, and double-click |
||||||||||
7 |
In the Actions toolbox, click the Objects category; then click Movie, Color, Methods, and double-click
|
||||||||||
8 |
Repeat steps 6 and 7 for all four colors, so that your code looks like this: |
||||||||||
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) } |
|||||||||||
9 |
Choose Control > Test Movie to change the color of the movie clip. |
For more information about the methods of the Color object, see Color (object) in the ActionScript Dictionary.
![]() ![]() ![]() |