// Bill. lee created in 2011.2.10 // version 1.0 package {public class color {// contructor, the constructors of use a number // ActionScript cannot overload public function color (color: string) {This. stringvalue = color;} // -------------- set value in different format ------------- // set value by INTEGER (real value) public function set realvalue (value: Number): void {This. R = value> 16; this. G = (value> 8) & 0xff; this. B = Value & 0xff;} public function setrgb (r: Number, G: Number, B: Number): void {This. R = r; this. G = g; this. B = B;} // set string value like "# ff0000" public function set stringvalue (value: string): void {// check var reg1: regexp =/# [0-9a-fa-f] {6}/; // # ff00000 var reg2: Regexp =/0x [0-9a-fa-f] {6}/; var S: string; if (reg1.test (value) {S = "0x" + value. substr (1, 6);} else if (reg2.test (value) {S = value;} else if (value. length = 0) // if it is "", the default value is black {S = "0x000000";} else {Throw new error ("color wrong ");} // var S: String = "0x" + value. substring (1, 7); this. realvalue = Number (s);} public function set R (value: Number): void {This. R = value;} public function set g (value: Number): void {This. G = value;} public function set B (value: Number): void {This. B = value;} // ------------------- get value in different format ----------------------- // to string like "# ff0000" Public Function get stringvalue (): String {return "#" + this. realvalue. tostring (16);} // get the real color value public function get realvalue (): number {var C: Number = r <16 | G <8 | B; // bit operation return C;} public function get R (): number {return this. r;} public function get G (): number {return this. g;} public function get B (): number {return this. b;} private var R: Number; private var G: Number; private var B: Number ;}}