0

I'd like to know how can I add blur in a certain area for example behind a movieclip, maybe a mask that will blur everything in the area of that moviclip.

I don't want to blur everything, just what's behind a movieclip :) Sort of like Apple is doing with their menus

rmaddy
  • 314,917
  • 42
  • 532
  • 579
ProgramKiddo
  • 313
  • 3
  • 12
  • http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filters/BlurFilter.html. I googled the flash API for you ;P – Neal Davis Oct 06 '16 at 20:29

1 Answers1

1

The only way to do this in AS3 is draw whatever is behind the MovieClip to a Bitmap, then blur the bitmap.


For example, say your MovieClip is a modal dialog of some sort with a semi-transparent background, you could use the following script (inside the MovieClip) to blur whatever is on the stage behind it onto a bitmap surface:

// create a bitmap surface to use as a blurred background
var blurData:BitmapData = new BitmapData(width, height, false);
var blur:Bitmap = new Bitmap(blurData);
addChildAt(blur, 0); // put the blur surface behind everything in the movieclip

// this function draws the portion of the stage that's behind the movieclip
// onto the bitmap surface, then blurs it
function drawBlurBehind():void {

    // fill the bitmap with the stage color first
    blurData.fillRect(blurData.rect, stage.color);

    // account for the coordinate offset of the stage and movieclip
    var offset:Point = globalToLocal(new Point());
    var matrix:Matrix = new Matrix();
    matrix.tx = offset.x;
    matrix.ty = offset.y;

    // hide the movieclip so it doesn't show up in the blurred background
    visible = false;

    // draw the stage behind the movieclip onto the bitmap
    blurData.draw(stage, matrix);

    // blur the background bitmap
    blurData.applyFilter(blurData, blurData.rect, new Point(), new BlurFilter(25, 25));

    // show the movieclip after the background has been blurred
    visible = true;
}

Note that this drawing is not "live" and any time anything changes (you move the movieclip or what's behind it changes) you have to redraw. You could use an ENTER_FRAME event handler to continually redraw every frame, which would basically make it live, but that will be relatively expensive so avoid it if you can.

Also note that this script draws and blurs the whole stage (excluding the movieclip), not what is strictly "behind" the movieclip. So if you want things to appear above the movieclip and not appear blurred behind the movieclip, you'll have to set those to visible=false while you draw the blurred background.

Aaron Beall
  • 49,769
  • 26
  • 85
  • 103
  • Well, that would blur everything but then you wouldn't be able to mask it down to a portion of the container (without masking out the whole container). If you want to blur a *portion* of the backdrop then you have to copy it to another bitmap surface. – Aaron Beall Oct 06 '16 at 20:56
  • Yes that's the problem, it would blur everything in the container. The OP is asking how to blur a portion of the stage. There's just no way to do that, the workaround is to copy, trim, and blur. The only generally reliable way to copy visually is to draw to a bitmap. – Aaron Beall Oct 06 '16 at 21:15