Win
Win

Reputation: 62260

Flash - ActionScript - Change fill color of a button in code

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!

Upvotes: 0

Views: 8386

Answers (1)

Boon
Boon

Reputation: 41480

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);

Upvotes: 4

Related Questions