views:

181

answers:

1

ActionScript 3 - CS5

I'm new to Flash and wondering how to change fill color from code. Something like this -

btnRed.fillColor = "0xff0000";

Thank you for your comment!

+3  A: 

Look into ColorTransform. All DisplayObject (i.e. Sprite, MovieClip, Shape, etc.) has a property called transform, which in turns contains a property called ColorTransform.

The code below makes it so a square with black fill color is changed to green:

var  square:Shape  = new  Shape();
square.graphics.beginFill(0x000000);
square.graphics.drawRect(0, 0, 200, 200);

var ct:ColorTransform = square.transform.colorTransform;
ct.color = 0x00FF00;
square.transform.colorTransform = ct;

addChild(square);
Boon
Thank you for your answer. Mine are buttons (each button has unique shape). Is there any way of changing fillColor of a button.
winmyan
If when you say buttons you mean fl.controls.Button then the answer provided will work. In fact, if you can *see* something on the screen in flash then it has a *transform* property, which in turn has a *colorTransform* property...
heavilyinvolved
Each button is a single map. I imported from Illustrator to flash library, and converted them to buttons (they are not rectangles). For now, I change the color of each county manually. I found out that I cannot change my buttons' fill color in code unless I convert those buttons to movie clips. Thank both of you for the answers; really appreicate it!
winmyan