The process for applying a filter to a display object is:
1. Create a new Filter object.
2. Create a temp array.
3. Copy the filters property from your display object to the temp array.
4. Add your new Filter object to the temp array.
5. Copy the temp array to the original display object filters property.
The reason for the copying out of the filters property is because AS3 does not support adding our new filter object directly to the display objects filter property.
The code will look like so:
// Parameters and default values for the GlowFilter() class are:
// GlowFilter(color:uint = 0xFF0000, alpha:Number = 1.0,
// blurX:Number = 6.0,
// blurY:Number = 6.0, strength:Number = 2,
// quality:int = 1, inner:Boolean = false,
// knockout:Boolean = false)
var _glow_filter:GlowFilter = new GlowFilter();
var _tmp_filter:Array = new Array();
var _demo_bitmap:Bitmap = new Bitmap(); // Empty, create your own bmp.
_tmp_filter = _demo_bitmap.filters;
_tmp_filter.push(_glow_filter);
_demo_bitmap.filters = _tmp_filter;
*UPDATE* (31Jan2010) : I like the tutorial here:
http://www.republicofcode.com/tutorials/flash/as3filters/
No comments:
Post a Comment