// ---------------------------------------------------------------------------------------------------------------------------------- // _brightness_* /** * Gets brightness using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @return Number Value of the brightness property */ public static function __brightness_get (p_obj: DisplayObject):Number { return getColorMatrix(p_obj).getBrightness(); }; /** * Changes brightness of a DisplayObject using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @param p_value Number Value of the brightness property (min: -100 / max: 100 / standard: 0) */ public static function __brightness_set (p_obj:DisplayObject, p_value:Number):void { var colorMatrix: ColorMatrix = new ColorMatrix(); colorMatrix.setBrightness(p_value); setColorMatrix(p_obj, colorMatrix); }; // ---------------------------------------------------------------------------------------------------------------------------------- // _contrast_* /** * Gets contrast using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @return Number Value of the contrast property */ public static function __contrast_get (p_obj: DisplayObject):Number { return getColorMatrix(p_obj).getContrast(); }; /** * Changes contrast of a DisplayObject using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @param p_value Number Value of the contrast property (min: -200 / max: 500 / standard: 0) */ public static function __contrast_set (p_obj:DisplayObject, p_value:Number):void { var colorMatrix: ColorMatrix = new ColorMatrix(); colorMatrix.setContrast(p_value); setColorMatrix(p_obj, colorMatrix); }; // ---------------------------------------------------------------------------------------------------------------------------------- // _saturation_* /** * Gets saturation using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @return Number Value of the saturation property */ public static function __saturation_get (p_obj: DisplayObject):Number { return getColorMatrix(p_obj).getSaturation(); }; /** * Changes saturation of a DisplayObject using ColorMatrix * * @param p_obj DisplayObject A Display Object instance * @param p_value Number Value of the saturation property (min: -300 / max: 300 / standard: 100) */ public static function __saturation_set (p_obj:DisplayObject, p_value:Number):void { var colorMatrix: ColorMatrix = new ColorMatrix(); colorMatrix.setSaturation(p_value); setColorMatrix(p_obj, colorMatrix); }; // ---------------------------------------------------------------------------------------------------------------------------------- // COLORMATRIX helper functions ----------------------------------------------------------------------------------------------------- /** * Helper method for getting the ColorMatrix of a DisplayObject * * @param p_obj DisplayObject A Display Object instance * @return ColorMatrix ColorMatrix of the Display Object */ private static function getColorMatrix(p_obj: DisplayObject): ColorMatrix { var filters: Array = p_obj.filters; var colorMatrix: ColorMatrix = new ColorMatrix(); var i:int = filters.length; while(--i > -1) { if(filters[i] is ColorMatrixFilter) { colorMatrix.matrix = filters[i].matrix.concat(); break; } } return colorMatrix; } /** * Helper method for setting the ColorMatrix of a DisplayObject * * @param p_obj DisplayObject A Display Object instance * @param p_value ColorMatrix A ColorMatrix instance */ private static function setColorMatrix(p_obj: DisplayObject, value: ColorMatrix): void { var filters: Array = p_obj.filters; var tFilters: Array = new Array(); var colorMatrix: ColorMatrix = value; var i:int = filters.length; while(--i > -1) { if(!(filters[i] is ColorMatrixFilter)) { tFilters.push(filters[i]); } } tFilters.push(colorMatrix.filter); p_obj.filters = tFilters; }