Sunday, November 30, 2008

Change color of movieclip (Actionscipt 2.0)

Here's the Code for changing color of a movieclip (given the movieclip is in white color)



changeMCColor=function (_mcName:String, _red:Number, _green:Number, _blue:Number, _newAlpha:Number){

// trace("_xmouse/Stage.width: "+_xmouse/Stage.width);
// var xPercent:Number = 1 - (_xmouse/Stage.width);
// var yPercent:Number = 1 - (_ymouse/Stage.height);
var matrix:Array = new Array();
if((_red>1)||(_green>1)||(_blue>1)||(_newAlpha>1)){//for 255 case
matrix = matrix.concat([_red/255, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, _green/255, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, _blue/255, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, _newAlpha/255, 0]); // alpha
}else{
matrix = matrix.concat([_red, 0, 0, 0, 0]); // red
matrix = matrix.concat([0, _green, 0, 0, 0]); // green
matrix = matrix.concat([0, 0, _blue, 0, 0]); // blue
matrix = matrix.concat([0, 0, 0, _newAlpha, 0]); // alpha
}

var filter:BitmapFilter = new ColorMatrixFilter(matrix);
eval("_root."+_mcName).filters = new Array(filter);
}

No comments: