I want to write the Glass Effect from AS2 to AS3 but I’ve got some errors. Could you help me?
AS2 working version
import flash.filters.*;
import flash.geom.*;
import flash.display.*;
class GlassWin extends MovieClip{
private var glassColor:Number=0xD9FFFF;
private var glassAlpha:Number=35;
private var mousePoint:Point;
private var alphaScreen:MovieClip;
private var blurScreen:MovieClip;
private var blurBitmap:BitmapData;
public function GlassWin(){
var w:Number=Math.floor(_width);
var h:Number=Math.floor(_height);
var lowDepth=0;
//всех поднимем на 2, чтоб освободить место для скринов
for(var i in this) {
if(this*.getDepth()<lowDepth)lowDepth=this*.getDepth();
_root.swapDepths.call(this*,this*.getDepth()+2);
}
//////////////
var bounds=getBounds(this);
alphaScreen=this.createEmptyMovieClip("alphaScreen",lowDepth+1);
blurScreen=this.createEmptyMovieClip("blurScreen",lowDepth);
alphaScreen._x=blurScreen._x=bounds.xMin;
alphaScreen._y=blurScreen._y=bounds.yMin;
alphaScreen.beginFill(glassColor,glassAlpha);
alphaScreen.lineTo(w,0);
alphaScreen.lineTo(w,h);
alphaScreen.lineTo(0,h);
alphaScreen.endFill();
////////
blurBitmap=new BitmapData(w,h);
blurScreen.attachBitmap(blurBitmap,0);
getScreen();
render();
}
function onPress(){
mousePoint=new Point(_xmouse,_ymouse);
onEnterFrame=render;
}
function onRelease(){
onEnterFrame=null;
}
function render(){
_x+=_xmouse-mousePoint.x;
_y+=_ymouse-mousePoint.y;
mousePoint=new Point(_xmouse,_ymouse);
getScreen();
updateAfterEvent();
}
function getScreen(){
var p:Point=new Point(_x,_y);
_parent.localToGlobal(p);
var tx:Number=-(p.x+blurScreen._x);
var ty:Number=-(p.y+blurScreen._y);
var mtrx=new Matrix(1,0,0,1,tx,ty);
_visible=false;
blurBitmap.draw(_root,mtrx);
_visible=true;
blurBitmap.applyFilter(blurBitmap,blurBitmap.rectangle,new Point(),new BlurFilter(10,10));
}
}
My version AS3 (getting some errors…)
package{
import flash.filters.*;
import flash.geom.*;
import flash.display.*;
import flash.events.*;
public class GlassWin extends MovieClip{
private var glassColor:Number=0xD9FFFF;
private var glassAlpha:Number=35;
private var mousePoint:Point;
private var alphaScreen:MovieClip;
private var blurScreen:MovieClip;
private var blurBitmap:BitmapData;
public function mouseDownHandler(event:MouseEvent){
mousePoint=new Point(mouseX,mouseY);
addEventListener(Event.ENTER_FRAME, render);
}
public function clickHandler(){
removeEventListener(Event.ENTER_FRAME, render);
}
public function render(e:Event){
x+=mouseX-mousePoint.x;
y+=mouseY-mousePoint.y;
mousePoint=new Point(mouseX,mouseY);
getScreen();
}
public function getScreen():void{
var p:Point=new Point(x,y);
parent.localToGlobal(p);
var tx:Number=-(p.x+blurScreen.x);
var ty:Number=-(p.y+blurScreen.y);
var mtrx=new Matrix(1,0,0,1,tx,ty);
visible=false;
blurBitmap.draw(stage,mtrx);
visible=true;
blurBitmap.applyFilter(blurBitmap,blurBitmap.rectangle,new Point(),new BlurFilter(10,10));
}
public function GlassWin(){
var w:Number=Math.floor(this.width);
var h:Number=Math.floor(this.height);
var lowDepth=0;
//всех поднимем на 2, чтоб освободить место для скринов
for(var i in this) {
if(this*.getDepth()<lowDepth)lowDepth=this*.getDepth();
stage.swapDepths.call(this*,this*.getDepth()+2);
}
//////////////
var bounds=getBounds(this);
var alphaScreen:MovieClip = new MovieClip();
addChild(alphaScreen);
var blurScreen:MovieClip = new MovieClip();
addChild(blurScreen);
alphaScreen.x=blurScreen.x=bounds.x;
alphaScreen.y=blurScreen.y=bounds.y;
alphaScreen.graphics.beginFill(glassColor,glassAlpha);
alphaScreen.graphics.lineTo(w,0);
alphaScreen.graphics.lineTo(w,h);
alphaScreen.graphics.lineTo(0,h);
alphaScreen.graphics.endFill();
////////
blurBitmap=new BitmapData(w,h);
var blurScreen1:Bitmap = new Bitmap(blurBitmap);
blurScreen.addChild(blurScreen1)
getScreen();
render();
addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
addEventListener(MouseEvent.CLICK, clickHandler);
}
}
}