I am trying to rebuild “Pixelator” class writen by Eric Hallander, becouse I need it for my personal site, and orginal class doesn’t give me all that I need. I thought I have everythig right scripted but after compilate debuger gives me an error:
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData$iinit()
at tmk::Pixelate/::pixelateOut()
this is code of my MainClass - calling a Pixelation effect:
package src {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import tmk.Pixelate;
public class MainClass extends MovieClip {
//vars
public function MainClass():void {
addImg();
}
private function addImg():void {
var image1:Bitmap = new Bitmap(new Img1(1,1));
var image2:Bitmap = new Bitmap(new Img2(1,1));
var pixelate:Pixelate = new Pixelate;
pixelate.it(image1, image2, 0.2, 20, 200);
}
}
}
Img1 and Img2 are a JPG bitmaps in .fla file library - with linkage names Img1, and Img2, assignet to flash.display.Bitmap
and the Pixelation class - which should pixelate my bitmap:
package tmk{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Matrix;
public class Pixelate extends Sprite {
//vars
public var pixelStart:Sprite;
public var pixelEnd:Sprite;
public var destination:DisplayObject;
public var pixelMatrix:Matrix;
public var pixelOverlay:Sprite;
public var pixelBitmap:Bitmap;
public var pixelBitmapData:BitmapData;
public var inSpeed:Number = 1;
public var outSpeed:Number = 1;
public var pixelSize:Number;
public var pixelMinSize:Number;
public var pixelMaxSize:Number;
public const PIXELATE_COMPLETE:String = "PIXELATE_COMPLETE";
public function Pixelate(){
trace("pixelate");
}
public function it(objectIn:DisplayObject, objectOut:DisplayObject, speed:Number, pixelMin:Number, pixelMax:Number):void {
pixelStart = new Sprite();
pixelEnd = new Sprite();
var objectData:BitmapData = new BitmapData(objectIn.width, objectIn.height, true, 0);
objectData.draw(objectIn);
pixelStart.addChild(new Bitmap(pixelBitmapData));
objectData = new BitmapData(objectOut.width, objectOut.height, true, 0);
objectData.draw(objectOut);
pixelEnd.addChild(new Bitmap(objectData));
pixelEnd.visible = objectIn.visible = objectOut.visible = false;
pixelOverlay = new Sprite();
pixelBitmap = new Bitmap(pixelBitmapData);
pixelOverlay.addChild(pixelBitmap);
addChild(pixelStart);
addChild(pixelEnd);
addChild(pixelOverlay);
inSpeed = inSpeed - speed;
outSpeed = outSpeed + speed;
pixelSize = pixelMin;
pixelMinSize = pixelMin;
pixelMaxSize = pixelMax;
addEventListener("PIXELATE_END", pixelateEnd);
addEventListener(Event.ENTER_FRAME, pixelateOut);
}
private function pixelateOut(e:Event):void {
pixelBitmapData = new BitmapData(pixelStart.width/pixelSize, pixelStart.height/pixelSize, true, 0);
pixelMatrix = new Matrix();
pixelMatrix.scale(1/pixelSize, 1/pixelSize);
pixelBitmapData.draw(pixelStart, pixelMatrix);
pixelBitmap.bitmapData = pixelBitmapData;
pixelBitmap.width = pixelStart.width;
pixelBitmap.height = pixelStart.height;
pixelSize *= outSpeed;
if (pixelSize >= pixelMaxSize) {
removeEventListener(Event.ENTER_FRAME, pixelateOut);
dispatchEvent(new Event("PIXELATE_TRANSITION"));
addEventListener(Event.ENTER_FRAME, pixelateIn);
}
}
private function pixelateIn(e:Event):void {
pixelBitmapData = new BitmapData(pixelEnd.width/pixelSize, pixelEnd.height/pixelSize, true, 0);
pixelMatrix = new Matrix();
pixelMatrix.scale(1/pixelSize, 1/pixelSize);
pixelBitmapData.draw(pixelEnd, pixelMatrix);
pixelBitmap.bitmapData = pixelBitmapData;
pixelBitmap.width = pixelEnd.width;
pixelBitmap.height = pixelEnd.height;
pixelMinSize *= inSpeed;
if (pixelSize <= pixelMinSize) {
removeEventListener(Event.ENTER_FRAME, pixelateOut);
dispatchEvent(new Event("PIXELATE_END"));
}
}
private function pixelateEnd(e:Event):void {
dispatchEvent(new Event(PIXELATE_COMPLETE));
if (pixelStart != null) {
removeChild(pixelStart);
}
if (pixelEnd != null) {
removeChild(pixelEnd);
}
pixelBitmapData.draw(pixelEnd);
pixelBitmap.bitmapData = pixelBitmapData;
pixelStart = null;
pixelEnd = null;
pixelBitmapData.dispose();
pixelBitmapData = null;
pixelBitmap = null;
pixelMatrix = null;
removeEventListener(Event.ENTER_FRAME, pixelateIn);
removeEventListener("PIXELATE_END", pixelateEnd);
}
}
}
I tried to search in Google - no effect. I had rewrite in on milion ways - no effect - allways the same error.
BTW. Event.PIXELATE_COMPLETE was added to use it in future, now it is not used.
What am I doing wrong? Thanks for all help and sugestions.
T.