How to change the color of a movieClip?
Happy New Year 2010 everyone :) Just getting back into the Flash groove, and having a simple question.
I have a movie(video player) where the color of the buttons changes. I've already drawn out the buttons and created a 1 color box(movieClip) that will be the background of all the buttons.
I've used ColorT开发者_JS百科ransform to change the color of a rectangle that I used code to create, but what is the simplest way to go about changing a color in a movieClip containing a graphic that you physically have drawn out.
Path to movieClip that I need to change the HEX value of: controls.btn_Sound.colorChip
If controls.btn_Sound.colorChip is a MovieClip or Sprite, you can use the drawing API to change its graphics properties.
So instead of:
colorChip=0xCCCCCC; btnColor_sound.color=colorChip;
do this:
controls.btn_Sound.colorChip.graphics.beginFill(colorChip, 1);
controls.btn_Sound.colorChip.lineStyle(1, 0x000000);
controls.btn_Sound.colorChip.drawRect(0, 0, 10, 10); // fill in this with your colorChip's dimensions
controls.btn_Sound.colorChip.endFill()
Thats a vey basic way to do it. You'll probably want to clear it out each time you switch colors, and maybe modify the line style. Look up the Graphics class and the Drawing API in the AS3 docs, those should help clarify this.
I used ColorMatrixFilter to alter color properties to my Sprites, MCs:
example:
var matrix:Array = new Array();
matrix=matrix.concat([0.5,0.5,0.5,0,0]);// red
matrix=matrix.concat([0.5,0.5,0.5,0,0]);// green
matrix=matrix.concat([0.5,0.5,0.5,0,0]);// blue
matrix=matrix.concat([0,0,0,1,0]);// alpha
var my_filter:ColorMatrixFilter=new ColorMatrixFilter(matrix);
my_sprite.filters=[my_filter];
here you are, a link to a good guide
精彩评论