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:

/**
 * Adds the universal glow to the display object.
 * @param displayObject The display object to receive the glow.
 * @param container The container to hold the newly created snapshot.GlowMC.PAGE_VECTOR.
 */
public static function addGlow( displayObject:DisplayObject, container:DisplayObjectContainer ):void
{
	// Capture an instance of the displayObject
	var rect:Rectangle = new Rectangle( -1, -1, displayObject.width + 2, displayObject.width + 2 );
	var bmd:BitmapData = new BitmapData( displayObject.width + 2, displayObject.height + 2, true, 0xFF );
	bmd.draw( displayObject, null, null, null, rect, true );
 
	// Apply the Capture
	var bitmap:Bitmap = new Bitmap( bmd );
	var filters:Array = container.filters;
	var glowFilter:GlowFilter = new GlowFilter();
	glowFilter.blurX = glowFilter.blurY = 10;
	glowFilter.inner = false;
	glowFilter.knockout = true;
	glowFilter.strength = 1;
	glowFilter.quality = 2;
	glowFilter.color = 0xFFFFFF;
 
	// Set
	filters[filters.length] = glowFilter;
	bitmap.filters = filters;
	bitmap.blendMode = "add";
	container.addChild( bitmap );
 
	// Clear vars
	rect = null;
	bmd = null;
	bitmap = null;
	filters = null;
	glowFilter = null;
}
 

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