简体   繁体   中英

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!

Look into ColorTransform . All DisplayObject (ie 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM