Generate Filter ActionScript 3 From DisplayObject’s
Filters in Flash are great, but I do have one big problem when working with them. As I’ve stated many times in my blog, I’m quite the ActionScript purist and I hardly touch the Flash IDE or FLA files. Thus visualizing a filter purely in code can be quite a pain. So sometimes, I’ll open up the Flash IDE and work on creating the filter settings with the help of the nice GUI controls. The problem is then converting all of my filter settings back into reusable ActionScript code.
To make this process a little easier, I took two minutes out to create an ActionScript class that accepts a display object as an argument, and then traces the ActionScript code needed in order to recreate the filter to the output console.
Check it out …
See the example below
Usage:
import com.thebackbutton.utils.FilterCodeUtil;
FilterCodeUtil.generateCode(myFilterDisplayObject);
Output:
import flash.filters.BlurFilter
import flash.filters.BevelFilter
import flash.filters.GlowFilter
import flash.filters.GradientBevelFilter
import flash.filters.DropShadowFilter
import flash.filters.ColorMatrixFilter
protected function getFilter():Array {
var f0:GlowFilter = new GlowFilter()
with (f0) {
quality = 1;
color = 16711680;
inner = false;
alpha = 1;
blurX = 12;
blurY = 12;
strength = 1;
knockout = false;
}
var f1:ColorMatrixFilter = new ColorMatrixFilter()
with (f1) {
matrix = [0.5599547624588013,-0.06101406738162041,0.3310593068599701,0,27.395000457763672,0.12372776120901108,0.7790034413337708,-0.07273124903440475,0,27.394996643066406,-0.18636742234230042,0.41579893231391907,0.6005684733390808,0,27.394996643066406,0,0,0,1,0];
}
var f2:BevelFilter = new BevelFilter()
with (f2) {
highlightColor = 16777215;
quality = 1;
highlightAlpha = 1;
type = 'inner';
shadowColor = 0;
shadowAlpha = 1;
blurX = 5;
blurY = 5;
distance = 5;
strength = 1;
angle = 44.999253346524966;
knockout = false;
}
var f3:GradientBevelFilter = new GradientBevelFilter()
with (f3) {
quality = 1;
type = 'inner';
colors = [16777215,16711680,0];
blurX = 5;
alphas = [1,0,1];
ratios = [0,128,255];
blurY = 5;
distance = 5;
strength = 1;
angle = 44.999253346524966;
knockout = false;
}
var f4:GradientBevelFilter = new GradientBevelFilter()
with (f4) {
quality = 1;
type = 'inner';
colors = [16777215,16711680,0];
blurX = 5;
alphas = [1,0,1];
ratios = [0,128,255];
blurY = 5;
distance = 5;
strength = 1;
angle = 44.999253346524966;
knockout = false;
}
var f5:GlowFilter = new GlowFilter()
with (f5) {
quality = 1;
color = 16711680;
inner = false;
alpha = 1;
blurX = 5;
blurY = 5;
strength = 1;
knockout = false;
}
var f6:DropShadowFilter = new DropShadowFilter()
with (f6) {
quality = 1;
color = 0;
inner = false;
alpha = 1;
blurX = 5;
blurY = 5;
distance = 5;
hideObject = false;
strength = 1;
angle = 44.999253346524966;
knockout = false;
}
var f7:BlurFilter = new BlurFilter()
with (f7) {
quality = 1;
blurY = 5;
blurX = 5;
}
return [f0,f1,f2,f3,f4,f5,f6,f7];
}




Thats pretty handy. You could also do this with JSFL and avoid the need to compile…..
Adobe has a handy little bit about using JSFL to get filters here:
http://www.adobe.com/devnet/flash/articles/jsfl_overview_03.html
However, a quick example would be to create a .jsfl script in your /Commands Directory and throw in this code:
var myDoc = flash.getDocumentDOM();
var myFilters = myDoc.selection[0].getFilters();
fl.outputPanel.clear();
if (item){
for( var i in myFilters ) {
fl.trace( myFilters[i].name );
for( var j in myFilters[i] ) {
fl.trace( j “: ” myFilters[i][j] );
}
}
}
Then you can just select the script from the commands menu and you’ll get your output. It’d still need some formatting for use in AS, but if you’re not familiar with JSFL its a great start….. This could probably become a great component as well…..
Hey John, thanks for the feedback. I guess I don’t use the IDE enough to take advantage of JSFL. I’ll have to look into creating a JSFL component in the coming week.
You dont realy need a component, a command would do that traced out the AS for each filter applied to the selected object.
This is true. The more I think about it, the JSFL command is probably more than enough to get the job done.
Banderas Antonio Naked…
…
Examination Male Genital…
…
2006 Cheats Madden…
…
Nubile Nude
…
…
Alex’s code will give you the correct values to set in AS3 code. The JSFL will only
give you the values that are valid for Flash CS3.
For instance:
Strength in Flash CS3 for the GlowFilter is 0 - 1000%
While in AS3 the documents say 0 - 255, but this is false as you will see if you run
Alex’s class on a movie clip with a filter on it. The correct value seems to be
Flash CS value / 100.
Thanks for the class.
Regards,
Rob.