+展开-ActionScript
package oreilly.cookbook{
import mx.effects.IEffectInstance;
import mx.effects.TweenEffect;
public class ConvolutionTween extends TweenEffect
{
//创建新EffectInstance时可能会传入的值如下:
public var toAlpha:Number;
public var fromAlpha:Number;
public var toColor:uint;
public var fromColor:uint;
public var fromMatrix:Array;
public var toMatrix:Array;
public var toDivisor:Number;
public var fromDivisor:Number;
public var toBias:Number;
public var fromBias:Number;
public function ConvolutionTween(target:Object=null)
{
super(target);
this.instanceClass = ConvolutionTweenInstance;
}
+展开-ActionScript
override protected function
initInstance(instance:IEffectInstance):void {
trace(" instance initialized ");
super.initInstance(instance);
// now that we've instantiated our instance, we can set
its properties
ConvolutionTweenInstance(instance).toAlpha = toAlpha;
ConvolutionTweenInstance(instance).fromAlpha =
fromAlpha;
ConvolutionTweenInstance(instance).toColor = toColor;
ConvolutionTweenInstance(instance).fromColor =
fromColor;
ConvolutionTweenInstance(instance).fromMatrix =
fromMatrix;
ConvolutionTweenInstance(instance).toMatrix = toMatrix;
ConvolutionTweenInstance(instance).toDivisor =
toDivisor;
ConvolutionTweenInstance(instance).fromDivisor =
fromDivisor;
ConvolutionTweenInstance(instance).toBias = toBias;
ConvolutionTweenInstance(instance).fromBias = fromBias;
}
override public function getAffectedProperties():Array {
trace(" return all the target properties ");
return [];
}
}
}
+展开-ActionScript
package oreilly.cookbook{
import flash.filters.ConvolutionFilter;
import mx.effects.Tween;
import mx.effects.effectClasses.TweenEffectInstance;
public class ConvolutionTweenInstance extends
TweenEffectInstance
{
private var convolutionFilter:ConvolutionFilter;
public var toAlpha:Number;
public var fromAlpha:Number;
public var toColor:uint;
public var fromColor:uint;
public var fromMatrix:Array;
public var toMatrix:Array;
public var toDivisor:Number;
public var fromDivisor:Number;
public var toBias:Number;
public var fromBias:Number;
public function ConvolutionTweenInstance(target:Object) {
super(target);
}
+展开-ActionScript
override public function play():void {
this.tween = new Tween(this,
[fromMatrix[0], fromMatrix[1], fromMatrix[2],
fromMatrix[3],fromMatrix[4],fromMatrix[5],
fromMatrix[6], fromMatrix[7], fromDivisor,
fromBias, fromAlpha, fromColor],
[toMatrix[0], toMatrix[1], toMatrix[2], toMatrix[3],
toMatrix[4], toMatrix[5], toMatrix[6], toMatrix[7], ,
toDivisor, toBias, toAlpha, toColor],duration);
convolutionFilter = new ConvolutionFilter(fromMatrixX,
fromMatrixY, fromMatrix, 1.0, 0, true, true,
fromAlpha, fromColor);
}
+展开-ActionScript
override public function onTweenUpdate(value:Object):void {
//get the filters from the target
var filters:Array = target.filters;
// Remove any existing Displacement filter to ensure
that ours is the only one
var n:int = filters.length;
for (var i:int = 0; i < n; i++) {
if (filters[i] is ConvolutionFilter)
filters.splice(i, 1);
} //create the new filter
convolutionFilter = new ConvolutionFilter(3, 3,
[value[0], value[1], value[2], value[3], value[4], value[5],
value[6], value[7]], value[8], value[9] true, true, value[10],
value[11]); //add the filter to the target
filters.push(convolutionFilter);
target.filters = filters;
}
}
}