AS類(lèi):顏色屬性ColorProperty
這個(gè)類(lèi)是對(duì)MovieClip類(lèi)擴(kuò)展,為MovieClip增加了這些屬性:
色調(diào):_color
亮度:_brightness
灰度:_grayscale
飽和度:_saturation
對(duì)比度:_contrast
反相:_invert
當(dāng)然,你也可以改寫(xiě)這個(gè)類(lèi),使之成為一個(gè)新類(lèi),而不是擴(kuò)展MovieClip類(lèi)。
用法(與_width,_height用法一樣):
import ColorProperty;
ColorProperty.init();
//色調(diào),用如0xFF0000的16進(jìn)制
//img._color=0x333399;
//trace(img._color);
//亮度,取值范圍為:-255~255
img._brightness = 100;
//trace(img._brightness)
//灰度,布爾值,true為灰度,false則反之。
//img._grayscale = true;
//trace(img._grayscale);
//飽和度,一般范圍為:0~3為宜
//img._saturation = 3;
//trace(img._saturation);
//對(duì)比度,取值范圍為:0~1
//img._contrast = 0.15;
//反相,布爾值,true為反相,false則反之。
//trace(img._contrast);
//img._invert=true;
代碼如下:
/**
* @Name:ColorProperty(MovieClip顏色屬性)
* 色調(diào):_color,亮度:_brightness,灰度:_grayscale,飽和度:_saturation,對(duì)比度:_contrast,反相:_invert
* @author:Flashlizi
* @version:1.0
*/
import flash.filters.ColorMatrixFilter;
class ColorProperty
{
//_matrix是ColorMatrixFilter類(lèi)的默認(rèn)恒等矩陣
//_nRed,_nGreen,_nBlue是計(jì)算機(jī)圖形顏色亮度的常量
//private static var _matrix : Array = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
private static var _nRed : Number = 0.3086;
private static var _nGreen : Number = 0.6094;
private static var _nBlue : Number = 0.0820;
function ColorProperty ()
{
}
public static function init ()
{
setColorProperty ();
//色調(diào)Color
MovieClip.prototype.addProperty ("_color", MovieClip.prototype.getColor, MovieClip.prototype.setColor);
//亮度Brightness(取值范圍為:-255~255)
MovieClip.prototype.addProperty ("_brightness", MovieClip.prototype.getBrightness, MovieClip.prototype.setBrightness);
//灰度Grayscale
MovieClip.prototype.addProperty ("_grayscale", MovieClip.prototype.getGrayscale, MovieClip.prototype.setGrayscale);
//飽和度Saturation(飽和度級(jí)別一般范圍為:0~3)
MovieClip.prototype.addProperty ("_saturation", MovieClip.prototype.getSaturation, MovieClip.prototype.setSaturation);
//對(duì)比度Contrast(取值范圍為:0~1)
MovieClip.prototype.addProperty ("_contrast", MovieClip.prototype.getContrast, MovieClip.prototype.setContrast);
//反相Invert
MovieClip.prototype.addProperty ("_invert", MovieClip.prototype.getInvert, MovieClip.prototype.setInvert);
}
private static function setColorProperty ()
{
//色調(diào)Color,getter&setter
MovieClip.prototype.getColor = function () : Number
{
return MovieClip.prototype._color;
}
MovieClip.prototype.setColor = function (nColor : Number) : Void
{
var colorStr : String = nColor.toString (16);
var nRed : Number = Number ("0x" + colorStr.slice (0, 2));
var nGreen : Number = Number ("0x" + colorStr.slice (2, 4));
var nBlue : Number = Number ("0x" + colorStr.slice (4, 6));
var Color_Matrix : Array = [1, 0, 0, 0, nRed, 0, 1, 0, 0, nGreen, 0, 0, 1, 0, nBlue, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Color_Matrix)];
MovieClip.prototype._color = nColor;
}
//亮度Brightness,getter&setter
MovieClip.prototype.getBrightness = function () : Number
{
return MovieClip.prototype._brightness;
}
MovieClip.prototype.setBrightness = function (offset : Number) : Void
{
var Brightness_Matrix : Array = [1, 0, 0, 0, offset, 0, 1, 0, 0, offset, 0, 0, 1, 0, offset, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Brightness_Matrix)];
MovieClip.prototype._brightness = offset;
}
//灰度Grayscale,getter&setter
MovieClip.prototype.getGrayscale = function () : Boolean
{
return MovieClip.prototype._grayscale;
}
MovieClip.prototype.setGrayscale = function (yes : Boolean) : Void
{
if (yes)
{
var Grayscale_Matrix : Array = [_nRed, _nGreen, _nBlue, 0, 0, _nRed, _nGreen, _nBlue, 0, 0, _nRed, _nGreen, _nBlue, 0, 0, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Grayscale_Matrix)];
MovieClip.prototype._grayscale = true;
} else
{
MovieClip.prototype._grayscale = false;
}
}
//飽和度Saturation,getter&setter
MovieClip.prototype.getSaturation = function () : Number
{
return MovieClip.prototype._saturation;
}
MovieClip.prototype.setSaturation = function (nLevel : Number) : Void
{
var srcRa : Number = (1 - nLevel) * _nRed + nLevel;
var srcGa : Number = (1 - nLevel) * _nGreen;
var srcBa : Number = (1 - nLevel) * _nBlue;
var srcRb : Number = (1 - nLevel) * _nRed;
var srcGb : Number = (1 - nLevel) * _nGreen + nLevel;
var srcBb : Number = (1 - nLevel) * _nBlue;
var srcRc : Number = (1 - nLevel) * _nRed;
var srcGc : Number = (1 - nLevel) * _nGreen;
var srcBc : Number = (1 - nLevel) * _nBlue + nLevel;
var Saturation_Matrix : Array = [srcRa, srcGa, srcBa, 0, 0, srcRb, srcGb, srcBb, 0, 0, srcRc, srcGc, srcBc, 0, 0, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Saturation_Matrix)];
MovieClip.prototype._saturation = nLevel;
}
//對(duì)比度Contrast,getter&setter
MovieClip.prototype.getContrast = function () : Number
{
return MovieClip.prototype._contrast;
}
MovieClip.prototype.setContrast = function (nLevel : Number) : Void
{
var Scale : Number = nLevel * 11;
var Offset : Number = 63.5 - (nLevel * 698.5);
var Contrast_Matrix : Array = [Scale, 0, 0, 0, Offset, 0, Scale, 0, 0, Offset, 0, 0, Scale, 0, Offset, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Contrast_Matrix)];
MovieClip.prototype._contrast = nLevel;
}
//反相Invert,getter&setter
MovieClip.prototype.getInvert = function () : Boolean
{
return MovieClip.prototype._invert;
}
MovieClip.prototype.setInvert = function (yes : Boolean) : Void
{
if (yes)
{
var Invert_Matrix : Array = [ - 1, 0, 0, 0, 255, 0, - 1, 0, 0, 255, 0, 0, - 1, 0, 255, 0, 0, 0, 1, 0];
this.filters = [new ColorMatrixFilter (Invert_Matrix)];
MovieClip.prototype._invert = true;
} else
{
MovieClip.prototype._invert = false;
}
}
}
}
下載:ColorProperty.rar
相關(guān)文章
土人系列AS入門(mén)教程--實(shí)戰(zhàn)篇
2008-02-02SWF自適應(yīng)布局技巧 (Rapid Flash Development)快速Flash開(kāi)發(fā)
當(dāng)我們開(kāi)發(fā)全站式Flash應(yīng)用時(shí),希望呈現(xiàn)一個(gè)鋪滿(mǎn)瀏覽器屏幕的Flash.2008-12-12FlashObject之Flash的檢測(cè)和嵌入Javascript腳本
FlashObject之Flash的檢測(cè)和嵌入Javascript腳本...2007-03-03FLASH自動(dòng)判斷域名然后轉(zhuǎn)向等操作
FLASH自動(dòng)判斷域名,如果不是你的域名,然后干什么你來(lái)定吧! 首先說(shuō)一下FLASH自已可以干什么!FLASH他可以判斷自已在哪個(gè)路徑下面,例如:2008-04-04關(guān)于為何要選擇xflash的對(duì)話(huà)
關(guān)于為何要選擇xflash的對(duì)話(huà)...2006-12-12使用 AllowNetworking Flash的世界安靜了
使用 AllowNetworking Flash的世界安靜了...2007-03-03做了個(gè)flash對(duì)mc移動(dòng)的控制,代碼很簡(jiǎn)單:)
做了個(gè)flash對(duì)mc移動(dòng)的控制,代碼很簡(jiǎn)單:)...2007-01-01給所有ActionScript初學(xué)者的一點(diǎn)建議 經(jīng)典
這篇文章主要給大家介紹了關(guān)于對(duì)ActionScript初學(xué)者的一點(diǎn)建議的相關(guān)資料,需要的朋友可以參考下2006-12-12