Flashscript classes (ActionScript 3) | Home | MX | MX 2004 | Flash 8 | Flash 9 |Flash 10 |PHP |Components | Snippets | Contact |

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()
Will change the filled areas of an image but not the lines.
NewColorMatrix
setOutlineColor()
Will change the line areas of an image but not th fill.
NewColorMatrix
transformColor()
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)
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)

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 changeBut:Button;
		public var cp:ColorPicker;
		private var mc:MovieClip;
		private var bmp:Bitmap;
		private var bd:BitmapData;
		private var myLoader:LoaderClassStatic;
		private static var cColor:Boolean = false;
		public function Newcolormatrix ():void
		{
			changeBut.label = "Change ColorMethod";
			changeBut.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 = 200;
			mc.y = 100;
			addChild (mc);
			bmp = (Bitmap(e.currentTarget.content));
			bmp.scaleX = 0.5;
			bmp.scaleY = 0.5;
			mc.addChild (bmp);
		}
		private function colorChange (event:Event):void
		{
			var newColor:String = ColorPicker(event.currentTarget).hexValue;
			var _ncm:NewColorMatrix = new NewColorMatrix(mc, newColor);
			if(cColor)
			{
				_ncm.setFillColor ();
			}
			else
			{
				_ncm.setOutlineColor ();
			}
		}
		private function changeHandler (event:Event):void
		{
			if(cColor)
			{
				cColor = false;
			}
			else
			{
				cColor = true;
			}
			var url:String = "images/A0.jpg";
			myLoader.initLoader (url, completed, this);
		}
	}
}