AS3改变显示对象亮度的其实代码是这样的

网上查到的基本上都是错的,连《ActionScript 3.0 Cookbook》里也不对,我的意思是跟Flash内容制作工具调的亮度不符,我就奇怪了,用调试模式测试了一个影片剪辑的亮度设置,结果就知道了
import flash.display.DisplayObject
import flash.geom.ColorTransform

//value取值范围-1~1,对应Flash内容制作工具里的-100%-100%
public function setBrightness(obj:DisplayObject,value:Number):void {
var colorTransformer:ColorTransform = obj.transform.colorTransform
var backup_filters:* = obj.filters
if (value >= 0) {
colorTransformer.blueMultiplier = 1-value
colorTransformer.redMultiplier = 1-value
colorTransformer.greenMultiplier = 1-value
colorTransformer.redOffset = 255*value
colorTransformer.greenOffset = 255*value
colorTransformer.blueOffset = 255*value
}else {
value=Math.abs(value)
colorTransformer.blueMultiplier = 1-value
colorTransformer.redMultiplier = 1-value
colorTransformer.greenMultiplier = 1-value
colorTransformer.redOffset = 0
colorTransformer.greenOffset = 0
colorTransformer.blueOffset = 0
}
  obj.transform.colorTransform = colorTransformer
  obj.filters = backup_filters
}
注意上面滤镜的备份,colorTransformer的设置会影响滤镜设置

你可能感兴趣的:(AS3改变显示对象亮度的其实代码是这样的)