NewColorMatrix

Package:
Class:
Inheritance:
biz.flashscript.bitmap
public class NewColorMatrix
Sprite
The NewColorMatrix class changes the color of bitmaps in various ways. Use the constructor new NewColorMatrix().
Public Methods
Method Defined By
NewColorMatrix(myBitmap:DisplayObject, newColor:String)
Creates a new instance of the NewColorMatrix class.
NewColorMatrix
setFillColor():void
Will change the filled areas of an image but not the lines.
NewColorMatrix
setOutlineColor():void
Will change the line areas of an image but not th fill.
NewColorMatrix
transformColor():void
Will do a simple color transformation to the new color set.
NewColorMatrix
setColorMatrix(mulPly:Number=1, setBright:Number=0, setContrast:Number=200, setHue:Number=0, setSat:Number=0):void
Will do a complex change to different brightness, hue and saturation.
NewColorMatrix
Events
Event Defined By

All events of the Sprite class

Sprite
Constructor Detail
NewColorMatrix(myBitmap:DisplayObject, newColor:String)  Constructor
public function NewColorMatrix(myBitmap:DisplayObject, newColor:String)
Intializes a new NewColorMatrix instance.

Parameters

  • myBitmap:DisplayObject ____ The object whose color will be changed.
  • newColor:String ____ A hexadecimal value for r, g and b.
Method Detail

setFillColor()  method
public function setFillColor():void

Will change the filled areas of an image but not the lines.

setOutlineColor()  method
public function setOutlineColor():void

Will change the line areas of an image but not th fill.

transformColor()  method
public function transformColor():void

Will do a simple color transformation to the new color set.

setColorMatrix()  method
public function setColorMatrix(mulPly:Number=1, setBright:Number=0, setContrast:Number=200, setHue:Number=0, setSat:Number=0):void

Will do a complex change to different brightness, hue and saturation.

Parameters

  • mulPly:Number=1 ____ Specifies the multiplication factor. Default is 1.
  • setBright:Number=0 ____ specifies the brightness. Default is 0.
  • setContrast:Number=200 ____ specifies the contrast. Default is 200.
  • setHue:Number=0 ____ specifies the hue setting. Default is 0.
  • setSat:Number=0 ____ specifies the color saturation. Default is 0.
Examples
Create a new fla file and name it NewColorMatrix.fla. Place the fla in the same folder as the biz folder. Put a ColorPicker component (cp), and one Button component (changeBut) on the stage. Then create an Actionscript file, name it Newcolormatrix.as and place this script.
package 
{
	import flash.display.*;
	import flash.events.*;
	import fl.controls.ColorPicker;
	import fl.controls.Button;
	import biz.flashscript.utils.LoaderClassStatic;
	import biz.flashscript.bitmap.NewColorMatrix;

	public class Newcolormatrix extends Sprite
	{
		public var fillBut:Button;
		public var outlineBut:Button;
		public var cp:ColorPicker;
		private static var mc:MovieClip;
		private var bmp:Bitmap;
		private var bd:BitmapData;
		private var myLoader:LoaderClassStatic;
		private var newColor:String = "000000";
		private var _ncm:NewColorMatrix;
		private var imageChanged:Boolean;
		private var butName:String = null;

		public function Newcolormatrix ():void
		{
			fillBut.label = "Set to 'Fill color'";
			fillBut.addEventListener (MouseEvent.CLICK, changeHandler);
			outlineBut.label = "Set to 'Outline color'";
			outlineBut.addEventListener (MouseEvent.CLICK, changeHandler);
			myLoader = new LoaderClassStatic();
			var url:String = "images/A0.jpg";
			myLoader.initLoader (url, completed, this);
			cp.addEventListener (Event.CHANGE, colorChange);
		}
		private function completed (e:Event):void
		{
			if (mc != null)
			{
				removeChild (mc);
				mc = null;
			}
			mc = new MovieClip();
			mc.x = 150;
			mc.y = 100;
			addChild (mc);
			mc.visible = false;
			bmp = (Bitmap(e.currentTarget.content));
			bmp.scaleX = 0.5;
			bmp.scaleY = 0.5;
			mc.addChild (bmp);
			mc.visible = true;
			_ncm = new NewColorMatrix(mc,newColor);
			imageChanged = true;
			if (butName != null)
			{
				changeColor (butName);
			}
		}
		private function colorChange (event:Event):void
		{
			newColor = ColorPicker(event.currentTarget).hexValue;
			var url:String = "images/A0.jpg";
			myLoader.initLoader (url, completed, this);
		}
		private function changeHandler (event:Event):void
		{
			butName = event.currentTarget.name;
			if (! imageChanged)
			{
				var url:String = "images/A0.jpg";
				myLoader.initLoader (url, completed, this);
			}
			else
			{
				changeColor (butName);
			}
		}
		private function changeColor (bName:String):void
		{
			if (bName == "outlineBut")
			{
				_ncm.setOutlineColor ();
			}
			else
			{
				_ncm.setFillColor ();
			}
			imageChanged = false;
		}
	}
}