AS3 Trace Out Filters Applied to a DisplayObject


/ Published in: ActionScript 3
Save to your folder(s)

All credit for this goes to Rob at calypso88.


Copy this code and paste it in your HTML
  1. function traceFilters(displayObject:DisplayObject):void{
  2. if(!displayObject || !displayObject.filters || displayObject.filters.length == 0) return trace('No filters found.');
  3. var s:String = '';
  4.  
  5. var formatHexNumber:Function = function(i:uint = 0):String{
  6. if(isNaN(i)) return '0x000000';
  7. var s:String = i.toString(16);
  8. while(s.length < 6) s = '0' + s;
  9. return '0x' + s.toUpperCase();
  10. }
  11.  
  12. for(var i:int = 0; i < displayObject.filters.length; ++i){
  13. if(displayObject.filters[i] == null) continue;
  14. var f:Object = displayObject.filters[i];
  15. if(i > 0) s += '\n';
  16. if(displayObject.filters.length > 1) s += '\t';
  17. var qcn:String = getQualifiedClassName(f);
  18. if(qcn == 'flash.filters::BevelFilter') s += 'new BevelFilter(' + f.distance + ', ' + f.angle.toFixed(3) + ', ' + formatHexNumber(f.highlightColor) + ', ' + f.highlightAlpha + ', ' + formatHexNumber(f.shadowColor) + ', ' + f.shadowAlpha + ', ' + f.blurX + ', ' + f.blurY + ', ' + f.strength + ', ' + f.quality + ', "' + f.type + '", ' + f.knockout + ')';
  19. if(qcn == 'flash.filters::BlurFilter') s += 'new BlurFilter(' + f.blurX + ', ' + f.blurY + ', ' + f.quality + ')';
  20. if(qcn == 'flash.filters::ColorMatrixFilter') s += 'new ColorMatrixFilter([' + f.matrix.map(function(element:*, index:int, arr:Array):String{ return (int(element) == element) ? String(element) : String(Number(element).toFixed(3)) }) + '])';
  21. if(qcn == 'flash.filters::ConvolutionFilter') s += 'new ConvolutionFilter(' + f.matrixX + ', ' + f.matrixY + ', [' + f.matrix.map(function(element:*, index:int, arr:Array):String{ return (int(element) == element) ? String(element) : String(Number(element).toFixed(3)) }) + '], ' + f.divisor + ', ' + f.bias + ', ' + f.preserveAlpha + ', ' + f.clamp + ', ' + formatHexNumber(f.color) + ', ' + f.alpha + ')';
  22. if(qcn == 'flash.filters::DropShadowFilter') s += 'new DropShadowFilter(' + f.distance + ', ' + f.angle.toFixed(3) + ', ' + formatHexNumber(f.color) + ', ' + f.alpha + ', ' + f.blurX + ', ' + f.blurY + ', ' + f.strength + ', ' + f.quality + ', ' + f.inner + ', ' + f.knockout + ', ' + f.hideObject + ')';
  23. if(qcn == 'flash.filters::GlowFilter') s += 'new GlowFilter(' + formatHexNumber(f.color) + ', ' + f.alpha + ', ' + f.blurX + ', ' + f.blurY + ', ' + f.strength + ', ' + f.quality + ', ' + f.inner + ', ' + f.knockout + ')';
  24. if(qcn == 'flash.filters::GradientBevelFilter') s += 'new GradientBevelFilter(' + f.distance + ', ' + f.angle.toFixed(3) + ', [' + f.colors.map(function(element:*, index:int, arr:Array):String{ return formatHexNumber(element as uint) }) + '], [' + f.alphas + '], ' + '[' + f.ratios + '], ' + f.blurX + ', ' + f.blurY + ', ' + f.strength + ', ' + f.quality + ', "' + f.type + '", ' + f.knockout + ')';
  25. if(qcn == 'flash.filters::GradientGlowFilter') s += 'new GradientGlowFilter(' + f.distance + ', ' + f.angle.toFixed(3) + ', [' + f.colors.map(function(element:*, index:int, arr:Array):String{ return formatHexNumber(element as uint) }) + '], [' + f.alphas + '], ' + '[' + f.ratios + '], ' + f.blurX + ', ' + f.blurY + ', ' + f.strength + ', ' + f.quality + ', "' + f.type + '", ' + f.knockout + ')';
  26. if(i + 1 < displayObject.filters.length) s += ','
  27. }
  28. trace(displayObject.name + '.filters = [' + s + ' ];');
  29. }

URL: http://www.calypso88.com/?p=610

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.