Skip to content

Flash Filters

by Colin on June 9th, 2010

I recently was working on a project where most Display Object's on my stage had an outer glow with an Add blend mode. In this instance, I got quite lucky because each object's filter settings were the same. It made a lot of sense to code the filter rather than duplicate the setting for the dozens of objects that were spread apart the project. Here's the basis of what I used:

  1. /**
  2. * Adds the universal glow to the display object.
  3. * @param displayObject The display object to receive the glow.
  4. * @param container The container to hold the newly created snapshot.GlowMC.PAGE_VECTOR.
  5. */
  6. public static function addGlow( displayObject:DisplayObject, container:DisplayObjectContainer ):void
  7. {
  8. // Capture an instance of the displayObject
  9. var rect:Rectangle = new Rectangle( -1, -1, displayObject.width + 2, displayObject.width + 2 );
  10. var bmd:BitmapData = new BitmapData( displayObject.width + 2, displayObject.height + 2, true, 0xFF );
  11. bmd.draw( displayObject, null, null, null, rect, true );
  12.  
  13. // Apply the Capture
  14. var bitmap:Bitmap = new Bitmap( bmd );
  15. var filters:Array = container.filters;
  16. var glowFilter:GlowFilter = new GlowFilter();
  17. glowFilter.blurX = glowFilter.blurY = 10;
  18. glowFilter.inner = false;
  19. glowFilter.knockout = true;
  20. glowFilter.strength = 1;
  21. glowFilter.quality = 2;
  22. glowFilter.color = 0xFFFFFF;
  23.  
  24. // Set
  25. filters[filters.length] = glowFilter;
  26. bitmap.filters = filters;
  27. bitmap.blendMode = "add";
  28. container.addChild( bitmap );
  29.  
  30. // Clear vars
  31. rect = null;
  32. bmd = null;
  33. bitmap = null;
  34. filters = null;
  35. glowFilter = null;
  36. }
  37.  

Also, it's best to add the filter object into a container so the blend mode works properly.

From → Flash

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS