# Pixelate effect using AS 3.0

**URL:** <https://forum.kirupa.com/t/pixelate-effect-using-as-3-0/240127>\
**Category:** Uncategorized\
**Created:** [September 29, 2007, 12:31pm UTC](https://forum.kirupa.com/t/pixelate-effect-using-as-3-0/240127 "2007-09-29T12:31:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ty2008](https://avatars.discourse-cdn.com/v4/letter/t/6bbea6/32.png) [@ty2008](https://forum.kirupa.com/u/ty2008)\
**Post date:** [September 29, 2007, 12:31pm UTC](https://forum.kirupa.com/t/pixelate-effect-using-as-3-0/240127/1 "2007-09-29T12:31:25Z")

</div>

i want to build this [http://www.senocular.com/flash/source.php?id=0.189](http://www.senocular.com/flash/source.php?id=0.189)  
i tryed to convert senocular’s pixelate effect from AS 2 to AS 3 but it’s not working.

this is senocular’s code

```auto

// create a movie clip to contain pixelated verson
// of the image in original_mc
this.createEmptyMovieClip( "pixelated_mc", 1 );
// place it below original_mc
pixelated_mc._y = original_mc._y + original_mc._height;

// create a variable to represent the current pixel size
var pixelSize = 1;

// every frame, increase pixelation
onEnterFrame = function(){
    // create a new bitmapData object based on original
    // movie clip size and current pixel size. This will
    // be used to pixelate the original
    var bitmapData = new flash.display.BitmapData( original_mc._width/pixelSize, original_mc._height/pixelSize, false );
    // attach the bitmap to pixelated_mc
    pixelated_mc.attachBitmap(bitmapData, 1);
    
    // create a matrix object used to scale the image 
    // which will be drawn from the original to bitmapData
    var scaleMatrix = new flash.geom.Matrix();
    // scale based on pixelSize
    scaleMatrix.scale(1/pixelSize, 1/pixelSize);
    
    // draw the original in BitmapData object at its reduced size
    bitmapData.draw( original_mc, scaleMatrix );
        
    // assure pixelated_mc matches the size of original_mc
    pixelated_mc._width = original_mc._width;
    pixelated_mc._height = original_mc._height;
    
    // increase pixelation
    pixelSize *= 1.1;
    
    // if pixel size is larger enough, return to 1
    if (pixelSize > 80){
        pixelSize = 1;
    }
}

```

and this is what i tryed

```auto
import flash.display.MovieClip;
import flash.events.Event;
import flash.geom.*;
import flash.display.Bitmap;
import flash.display.BitmapData;

var pixelated_mc:MovieClip = new MovieClip();
addChild(pixelated_mc);
pixelated_mc.y = original_mc.y + original_mc.height;

var pixelSize = 1;

this.addEventListener(Event.ENTER_FRAME, pixelate);

function pixelate(event:Event){
    var bitmapData:BitmapData = new BitmapData( original_mc.width/pixelSize, original_mc.height/pixelSize, false );
    var bitmap:Bitmap = new Bitmap(bitmapData);
    pixelated_mc.addChild(bitmap);
    var scaleMatrix:Matrix = new Matrix();
    scaleMatrix.scale(1/pixelSize, 1/pixelSize);
    bitmapData.draw( original_mc, scaleMatrix );
    pixelated_mc.width = original_mc.width;
    pixelated_mc.height = original_mc.height;
    pixelSize *= 1.1;
    if (pixelSize > 80){
        pixelSize = 1;
    }
}

```

could somebody please tell me what is not right ?  
thanks
