Changing Colors with ActionScript in Flash (AS3)

This is one of those cases where the ActionScript required is not very intuitive, but once you've got it, it is very easy to use. The color of any movie clip instance can be changed dynamically using three lines of script (below). In this example, there is a big rectangle covering the entire Stage. Each button changes the color of the rectangle.

You need to upgrade your Flash player (v.9 or later) to view this example.

First, you declare a variable for the colorTransform property of the specific movie clip instance (in this case, that instance is named bg_mc):

var newColor:ColorTransform = bg_mc.transform.colorTransform;

The variable name (newColor) is then used to store a specified color, which is subsequently applied to the movie clip instance:

newColor.color = 0x00ff00;
bg_mc.transform.colorTransform = newColor;

If you download the FLA, you'll find that the ActionScript is all in Frame 1 on the Timeline.

While normal hexadecimal codes for Web colors have the format of six numerals (for example: 33cc66), ActionScript requires us to add 0x in front of the usual six.

If you need help with buttons, see this tutorial: Flash Basics: AS3 Buttons.

DOWNLOAD The files can be downloaded from this folder.

Education use: This package was created as an example for my journalism students. It is not intended to be used commercially.

Use and re-use: Changing Colors with ActionScript in Flash (AS3) by Mindy McAdams is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
Creative Commons License

Updated 4 March 2011