Skip to content


BlurFilter Animation

A simple demonstration that animates a blur filter.

Here is the main document class:

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import fl.controls.Button;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.filters.BitmapFilter;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.GlowFilter;
	import flash.filters.BlurFilter;
	import flash.geom.Point;

	public class Main extends Sprite
	{
		private var ai:Image;

		private var bmd:BitmapData = new BitmapData(550, 400, true, 0xffffff); // this will cover the whole movie
		private var bm:Bitmap = new Bitmap(bmd);
		private var bf:BlurFilter = new BlurFilter(10, 10, 10);

		private var startBtn:Button;

		public function Main()
		{
			var ai:Image = new Image();
			addChild(ai);

			addChild(bm);

			// add the button
			var startBtn = new Button();
            startBtn.width = 100;
            startBtn.height = 30;
            startBtn.move ( stage.stageWidth - startBtn.width - 10, stage.stageHeight - startBtn.height - 10 );
            startBtn.label = "Start Animation";
            addChild(startBtn);

            startBtn.addEventListener(MouseEvent.CLICK, beginLoop);
		}

		private function beginLoop(e:MouseEvent):void
		{
			addEventListener(Event.ENTER_FRAME, loop);
		}

		private function loop(e:Event):void
		{
			bmd.draw(this);
			bmd.applyFilter(bmd,bmd.rect,new Point(0,0),bf);
			bmd.scroll(5,-5);
		}
	}
}

A simple class to load in my image:

package {
    import flash.display.Sprite;
    import flash.events.Event;
	import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.net.URLRequest;

    public class Image extends Sprite {
		private var imgLoader:Loader;

        public function Image() {
            loadImage();
        }

		private function loadImage():void {
			// Load in the image
			imgLoader = new Loader();
			imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
			imgLoader.load(new URLRequest("http://manewc.com/projects/flash/GlowFilterDemo/gahlordSmall.jpg"));
        }

		private function imageLoaded(e:Event):void
        {
			imgLoader.x = stage.stageWidth / 2 - (imgLoader.width / 2);
			imgLoader.y = stage.stageHeight / 2 - (imgLoader.height / 2);
            addChild(imgLoader);
        }
    }
}

Posted in Actionscript 3, Image Effects.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.