Codice PHP:
import mx.transitions.*;
import mx.transitions.easing.*;
import flash.filters.ColorMatrixFilter;
class flash.PhotoMatrixMotion {
/*
Elenco degli effetti disponibili
"normal", "luminance", "negative", "satured", "in_satured", "hue", "contrast", "in_contrast", "deep_red", "deep_blue", "deep_yellow", "fluorescent", "sepia"
*/
private var normalMatrix:Array = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
private var luminanceMatrix:Array = [1, 0, 0, 0, 255, 0, 1, 0, 0, 255, 0, 0, 1, 0, 255, 0, 0, 0, 1, 255];
private var negativeMatrix:Array = [-1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255, 0, 0, 0, 1, 0];
private var saturedMatrix:Array = [0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0.3086, 0.6094, 0.082, 0, 0, 0, 0, 0, 1, 0];
private var in_saturedMatrix:Array = [3.0742, -1.8282, -0.246, 0, 0, -0.9258, 2.1718, -0.246, 0, 0, -0.9258, -1.8282, 3.754, 0, 0, 0, 0, 0, 1, 0];
private var hueMatrix:Array = [-0.574, 1.43, 0.144, 0, 0, 0.426, 0.43, 0.144, 0, 0, 0.426, 1.43, -0.856, 0, 0, 0, 0, 0, 1, 0];
private var contrastMatrix:Array = [0, 0, 0, 0, 63.5, 0, 0, 0, 0, 63.5, 0, 0, 0, 0, 63.5, 0, 0, 0, 1, 0];
private var in_contrastMatrix:Array = [11, 0, 0, 0, -635, 0, 11, 0, 0, -635, 0, 0, 11, 0, -635, 0, 0, 0, 1, 0];
private var deep_redMatrix:Array = [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0];
private var deep_blueMatrix:Array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
private var deep_yellowMatrix:Array = [0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0];
private var fluorescentMatrix:Array = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0];
private var sepiaMatrix:Array = [0.35, 0.35, 0.35, 0, 0, 0.30, 0.30, 0.30, 0, 0, 0.21, 0.21, 0.21, 0, 0, 0, 0, 0, 1, 0];
// Variabili della classe
private var __target:MovieClip;
private var __initialMatrix:Array;
private var __finalMatrix:Array;
private var __easeType;
private var __time:Number;
private var __useSeconds:Boolean;
// Eventi
public var onMotionFinished:Function;
// Costruttore della classe
function PhotoMatrixMotion(target:MovieClip, from:Object, to:Object, easeType:Function, time:Number, useSeconds:Boolean) {
__target = target;
__initialMatrix = return_matrix(from);
__finalMatrix = return_matrix(to);
__easeType = easeType;
__time = time;
__useSeconds = useSeconds;
}
private function return_matrix(effect):Array {
if (typeof(effect) == "string") {
var matrix:Array = this[effect+"Matrix"].slice(0, this[effect+"Matrix"].length-1);
return matrix;
} else {
var matrix:Array = effect.slice(0, effect.length);
return matrix;
}
}
private function __process__(target:MovieClip, from:Array, to:Array, easeType:Function, time:Number, useSeconds:Boolean):Void {
target.filters = [new ColorMatrixFilter(from)];
var path:Object = this;
for (var i = 0; i<from.length; i++) {
this['tw'+i] = new Tween(from, i.toString(), easeType, from[i], to[i], time, useSeconds);
this['tw0'].onMotionChanged = function() {
target.filters = [new ColorMatrixFilter(from)];
};
this['tw0'].onMotionFinished = function() {
path["onMotionFinished"]();
};
}
}
public function startMotion () {
if (__target != undefined) {
__process__(__target, __initialMatrix, __finalMatrix, __easeType, __time, __useSeconds);
}
}
public function set target (m:MovieClip) {
__target = m;
}
public function get target ():MovieClip {
return __target;
}
public function set fromMatrix (o:Object) {
__initialMatrix = return_matrix(o);
}
public function get fromMatrix ():Object {
return __initialMatrix;
}
public function set toMatrix (o:Object) {
__finalMatrix = return_matrix(o);
}
public function get toMatrix ():Object {
return __finalMatrix;
}
public function get matrix():Array {
return this['__initialMatrix'];
}
}
e l'ho testata con questo codice: