A color class for ActionScript

Source: Internet
Author: User
// 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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.