ActionScript 3 颜色

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 颜色相关的知识,希望对你有一定的参考价值。

package com.luracast {
 
    /**
     * Set of funtions for handling color values in different format
     * @author R.Arul Kumaran [arul@luracast.com]
     * For more code keep visiting [www.luracast.com/all/blog]
     */
    public class ColorUtil {
        /**
         * returns a string representing the HEX value
         * for the specified R,G,B values
         * @param r red value (0-255)
         * @param g green value (0-255)
         * @param b blue value (0-255)
         * @return HEX String
         * @example
         * trace(ColorUtil.getHexStr(255,255,255));
         * //traces "ffffff"
         */
        public static function getHexStr(r:uint, g:uint, b:uint):String {
            return twoDigit(r.toString(16)) + 
				twoDigit(g.toString(16)) + 
				twoDigit(b.toString(16));
        }
 
        /**
         * returns the HEX value for the specified R,G,B values
         * @param r red value (0-255)
         * @param g green value (0-255)
         * @param b blue value (0-255)
         * @return HEX number
         * @example
         * trace(ColorUtil.getHex(255,255,255));
         * //traces 16777215
         */
        public static function getHex(r:uint, g:uint, b:uint):uint {
            return r << 16 | g << 8 | b;
        }
 
        /**
         * returns the RGB (as Object) for the
         * specified HEX value
         * @param Hex Hexadecimal number
         * @return Object with properties r, g, and b
         * @example
         * trace(ColorUtil.HexToRGB(0x0c0c0c).r);
         * //traces 12 (the red value)
         */
        public static function Hex2RGB(Hex:uint):Object {
            return { r: HEX >> 16, g: (HEX >> 8) & 
				0xff, b: HEX & 0xff };
        }
 
        /**
         * adds "0" in front if the string is only
         * one digit. Also useful for converting date time strings
         * @param str number given as string
         * @return converted string with a 0 prefix when needed
         * @example
         * var myDate = new Date();
         * var timeStr = ColorUtil.twoDigit(myDate.getHours())+
         * ColorUtil.twoDigit(myDate.getMinutes());
         * trace(timeStr);
         * //traces "01:09"
         */
        public static function twoDigit(str:String):String {
            return str.length == 1 ? "0" + str : str;
        }
		function fixColorCode($color:String) :String
		{
		   var submittedColor:String = $color;
		   var validColor:String;
		   var pattern:RegExp = /#/;

		   submittedColor = $color.replace(pattern,"");

		   pattern = /0x/;
		   if (submittedColor.substring(0,2) != "0x") {
			  validColor = "0x"+submittedColor;
		   } else {
			  validColor = submittedColor;
		   }

			return validColor;

		}
 
    }
}

以上是关于ActionScript 3 颜色的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 AS3 HSB颜色(对象)到RGB颜色(对象)

ActionScript 3 ls的bash颜色

ActionScript 3 常用颜色值作为常量

ActionScript 3 AS3随机颜色

ActionScript 3 颜色

ActionScript 3 vim颜色语法