Codice PHP:
/**
* @class Mirror
*
* ----------------------------------------------------------------------------------------------------------
* @file Mirror.as
* @size 4.686 byte
* @version 1.0.1 - ActionScript 3.0 compliance
* @author Andrea Milillo
* @date 22/01/2009
* @modify 01/06/2009 11.02
* @site [url]http://www.v2online.it[/url]
*/
/**
Version note:
*/
/*
Licensed under the MIT License
Copyright (c) 2009 Andrea Milillo
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
package {
import flash.display.*;
import flash.geom.*;
public class Mirror extends Sprite {
private var __t:DisplayObject;
private var __d:Number;
private var __o:Number;
private var __u:Number;
private var __b:Bitmap;
private var __g:GradientShape;
private var __v:Array;
/**
* @method Mirror Mirror ([target:DisplayObject=null, distance:Number=0, opacity:Number=1, uncovered:Number=1])
* @param target:DisplayObject Opzionale - l'oggetto target da cui ricavare lo specchio
* @param distance:Number Opzionale - la distanza verticale tra il clip originale e il suo specchio
* @param opacity:Number Opzionale - l'opacità in un valore da 0 a 1, della maschera che copre lo specchio
* @param uncovered:Number Opzionale - la parte scoperta in un valore da 0 a 1, della maschera che copre lo specchio
*/
public function Mirror (t:DisplayObject=null, d:Number=0, o:Number=1, u:Number=1) {
__t = t;
__d = d;
__o = o;
__u = u;
__init__();
}
private function __init__ () {
if(__t != null) {
__b = new Bitmap();
__g = new GradientShape(__t.width, __t.height*__u, __o);
__b.cacheAsBitmap = __g.cacheAsBitmap = true;
__b.mask = __g;
__v = [];
addChild(__b);
addChild(__g);
__v.push(new BitmapData(__t.width, __t.height, true, 0));
__v.push(new Matrix());
__v.push(__t.getRect(__t));
__v[1].translate(-__v[2].x, -(__v[2].height+__v[2].y));
__v[1].scale(1, -1);
__v[0].draw(__t, __v[1]);
__b.bitmapData = __v[0];
__b.x = __g.x = __v[2].x;
__b.y = __g.y = __v[2].y;
x = __t.x;
y = __t.y+__t.height+__d;
}
}
public function refresh () {
try {
while(numChildren > 0) {
removeChildAt(numChildren-1);
}
__init__();
} catch(e) {}
}
public function set target (t:DisplayObject) {
__t = t;
}
public function get target ():DisplayObject {
return __t;
}
public function set distance (d:Number) {
__d = d;
}
public function get distance ():Number {
return __d;
}
public function set opacity (o:Number) {
__o = o;
}
public function get opacity ():Number {
return __o;
}
public function set uncovered (u:Number) {
__u = u;
}
public function get uncovered ():Number {
return __u;
}
}
}
import flash.display.GradientType;
import flash.display.Shape;
import flash.display.SpreadMethod;
import flash.geom.Matrix;
internal class GradientShape extends Shape {
public function GradientShape (w:Number, h:Number, a:Number) {
var fillType:String = GradientType.LINEAR;
var colors:Array = [0, 0];
var alphas:Array = [a, 0];
var ratios:Array = [0, 255];
var matr:Matrix = new Matrix();
matr.createGradientBox(w, h, 90/180*Math.PI, 0, 0);
var spreadMethod:String = SpreadMethod.PAD;
graphics.beginGradientFill(fillType,colors,alphas,ratios,matr,spreadMethod);
graphics.drawRect(0, 0, w, h);
graphics.endFill();
}
}
Di base si usa così: