Quick Tip: uint To 6 Digit RGB Hex

Shortest possible, simple / no looping method of getting hex string from color is:

var color:uint = 0x00ff00;
var hex:String = color.toString(16);

trace("00000".substr(0, 6 - hex.length) + hex);
// output 00ff00

trace("#00000".substr(0, 7 - hex.length) + hex);
// output #00ff00

Color Picker Not Boring Anymore

For my next project, I needed some lightweight color picker that would be usable but not boring. Nice challenge. So I have created ColorCircle class that may work as a color picker while it dispatches all the necessary ColorCircleEvent-s. I made this class a little dynamic, so you can create custom color pickers on runtime using RGB palette, Black to White fade, solid color or current color with any defined radius (inner + outer) you want.

To create donut shapes I have used shape with lineStyle+drawCircle+cacheAsBitmap drawed over original graphics using BlendMode.ALPHA. To browse RGB pelette there is a paletteColor() method that crawls all color spectrum based on position (0 to 1).

Read the rest of this entry »

Quick tip: Contrast & Brightness In ActionScript 3

There are multiple libraries that lets you adjust contrast, brightness, hue, saturation. Lets have look at some:

fl.motion.AdjustColor class is a part of Flash CS4:

import flash.filters.ColorMatrixFilter;
import fl.motion.AdjustColor;
// AdjustColor class location:
// Adobe Flash CS4/Common/Configuration/ActionScript 3.0/projects/Flash/src/fl/motion/AdjustColor.as

var color:AdjustColor = new AdjustColor();
color.brightness = brightness;
color.contrast = contrast;
color.hue = 0;  
color. saturation = 0;
image.filters = [new ColorMatrixFilter(color.CalculateFinalFlatArray())];

Read the rest of this entry »