Using Filters With Actionscript 3.0

September 12, 2008 – 11:06 pm

You can use some of the filters which is being use in image programs such a Photoshop in Flash. Of course you can do this in IDE or you can do this by Actionscript. I will only mention how you can do it in Actionscript. The numbers of filters you an use in Actionscript is not just 7 or 8. Actually I can say this number is been decided by the user. This is more like up to your creativity and curiosity. You can also create new filters and manipulate them way you want. The other point I want to touch is new version of Flash Player (Code Name: Astro) has a special way to make your own filters. The filter made by a small program called Pixel Bender. But I explain and cover that with more detail in next articles.

Creating and Applying New Filter

Creating new filter is easy. Creating new filter is not different than a creating object. All you have to do create new Filter object with new statement than pass the parameters which is required. Most simple and most used one is Blur Filter;

  1. var blurFilt:BlurFilter = new BlurFilter (10, 10, BitmapFilterQuality.HIGH);

The blur filter takes 3 parameter. First one is blur amount that you want to apply x coordinate. Second one is amount of blut that you want to apply to y coordinate. The third parameter is the quality of blur which will be applied to display object. We can also show the code like this;

  1. var blurFilt:BlurFilter = new BlurFilter (blurX, blurY, BitmapFilterQuality.HIGH);

Our filter is ready, so how we are going to apply our filter to display abject? There are two ways fort his. First is using the filters property of the display object class. Second is using applyFilter method of BirmapData Class. In this article I will use the filters property.

  1. my_mc.filters = [blurFilt];

As you see, assigning filter is not different than assigning a x property for the display object. The point I want to mention is filters property is been build up as a array because this way you can assign more than one filter to display object.

Applying More Than One filter to Display Objects

As I mention above using more than a filter is same is using one filter. All you have to do is add filter names to filter array.

  1. var blurFilt:BlurFilter = new BlurFilter (10, 10, BitmapFilterQuality.HIGH);
  2. var shadowFilt:DropShadowFilter = new DropShadowFilter(10,45,0×999999,1.0, 5,5);
  3. my_mc.filters = [blurFilt, shadowFilt];

Removing Filters

You may want to remove the filters you are using after while. In this case all you have to do is removing element from filter array. If you want to remove all filters that you apply to display object is enough to assign null variable to filters property.

  1. my_mc.filters = null;

Of course if you want to remove only one filter out of 3 or 4 filter, what you can do is create a new array assign all the filters from filters property and than remove filter you want. After you remove which filter you want you can assign to array to filters property again.

Filter Examples

I use couple filters in example below. You can also see the code which has been use in filter on right side in text area. I just give the basic information about how you can use the filters. If you curious about the other filters in flash.filters package and also learn what are the property they takes you can check link at below.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/package-detail.html

Source Codes
Take Care
Engin Yöyen


  1. 1 Trackback(s)

  2. Sep 14, 2008: Engin Yöyen - Stay Updated On Web » Blog Archive » First Look To Pixel Bender

Leave a Reply