{"id":381,"date":"2011-07-21T23:38:20","date_gmt":"2011-07-21T22:38:20","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=381"},"modified":"2011-07-22T08:55:37","modified_gmt":"2011-07-22T07:55:37","slug":"jsfl-copy-filters-stack-from-flash-ide-into-actionscript-2-or-3-code","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2011\/07\/21\/jsfl-copy-filters-stack-from-flash-ide-into-actionscript-2-or-3-code\/","title":{"rendered":"JSFL &#8211; copy filters stack from Flash IDE into ActionScript 2 or 3 code"},"content":{"rendered":"<p>Hi,<\/p>\n<p>working with designers one will always get into a problem of replication IDE based filters via code, it&#8217;s not a pleasant task nor quick as well, but what about if we could actually make it quick and pleasant? Well, that would be something.<\/p>\n<p><!--more--><\/p>\n<p>To the rescue comes JSFL, namely <a title=\"document.getFilters() documentation\" href=\"http:\/\/help.adobe.com\/en_US\/Flash\/10.0_ExtendingFlash\/WS5b3ccc516d4fbf351e63e3d118a9024f3f-7e08.html\">document.getFilters()<\/a>, this method returns list of <a title=\"Filter object\" href=\"http:\/\/help.adobe.com\/en_US\/Flash\/10.0_ExtendingFlash\/WS5b3ccc516d4fbf351e63e3d118a9024f3f-7f85.html\">Filter objects<\/a> applied to the selected element.<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nvar listOfFilters = document.getFilters();\r\nfl.trace(&quot;\/\/Filters found: &quot;+listOfFilters.length);\r\nfor(var i=0; i&lt;listOfFilters.length; i++)\r\n{\r\n\tfl.trace(&quot;\/\/----------------------------\/\/&quot;);\r\n\tfl.trace(&quot;\/\/Filter#&quot;+i);\r\n\tfl.trace(&quot;\/\/----------------------------\/\/&quot;);\r\n\tfor(var filterProperty in listOfFilters[i])\r\n\t{\r\n\t\tfl.trace(&quot;\/\/&quot;+filterProperty + &quot;=&quot; + listOfFilters[i][filterProperty]);\r\n\t}\r\n}\r\n\r\n<\/pre>\n<p>Now because we know how to read filters and it&#8217;s values all we need to do:) is to write it as an ActionScript code, it is as easy as it sounds but to be honest it is lengthy as well. The only one problem was with Adjust Color filter where I had to use external library, to do this I have converted AS2 version of <a href=\"http:\/\/gskinner.com\">Grant Skinner<\/a>&#8216;s <a title=\"Grant Skinner - ColorMatrix\" href=\"http:\/\/gskinner.com\/blog\/archives\/2005\/09\/flash_8_source_.html\">ColorMatrix<\/a> class with his permission.<\/p>\n<p>Below is the sample file with original and recreated filter stack, further below is the output generated by my JSFL script.<br \/>\n[kml_flashembed publishmethod=&#8221;dynamic&#8221; fversion=&#8221;9.0.0&#8243; replaceId=&#8221;copy_filters_example_swf&#8221; movie=&#8221;\/blog\/wp-content\/uploads\/2011\/07\/copy_filters_example.swf&#8221; width=&#8221;400&#8243; height=&#8221;400&#8243; targetclass=&#8221;flashmovie&#8221;]<\/p>\n<p><a href=\"http:\/\/adobe.com\/go\/getflashplayer\"><img src=\"http:\/\/www.adobe.com\/images\/shared\/download_buttons\/get_flash_player.gif\" alt=\"Get Adobe Flash player\" \/><\/a><\/p>\n<p>[\/kml_flashembed]<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\/\/Filters found: 3\r\n\/\/----------------------------\/\/\r\n\/\/Filter#0\r\n\/\/----------------------------\/\/\r\nimport flash.filters.BitmapFilterQuality;\r\nimport flash.filters.ColorMatrixFilter;\r\n\r\nvar f0:ColorMatrixFilter = new ColorMatrixFilter();\r\n\r\n\/\/brightness,contrast,hue,saturation\r\nvar mat0:Array = [0.027595657749800967,-0.02451758146094174,0.9969219237111409,0,31,0.34847929546609796,0.8648610723428862,-0.21334036780898413,0,31.000000000000007,-0.5809541736616611,1.4046113011763652,0.1763428724852959,0,30.999999999999996,0,0,0,1,0]\r\nf0.matrix = mat0;\r\n\/\/----------------------------\/\/\r\n\/\/Filter#1\r\n\/\/----------------------------\/\/\r\nimport flash.filters.DropShadowFilter;\r\n\r\nvar f1:DropShadowFilter = new DropShadowFilter();\r\n\r\n\/\/angle,blurX,blurY,color,distance,hideObject,inner,knockout,quality,strength\r\nf1.angle = 45;\r\nf1.blurX = 5;\r\nf1.blurY = 5;\r\nf1.alpha = 1;\r\nf1.color = 0x000000;\r\nf1.distance = 5;\r\nf1.hideObject = false;\r\nf1.inner = false;\r\nf1.knockout = false;\r\nf1.quality = BitmapFilterQuality.LOW;\r\nf1.strength = 1;\r\n\/\/----------------------------\/\/\r\n\/\/Filter#2\r\n\/\/----------------------------\/\/\r\nimport flash.filters.BitmapFilterType;\r\nimport flash.filters.BevelFilter;\r\n\r\nvar f2:BevelFilter = new BevelFilter();\r\n\r\n\/\/angle,blurX,blurY,distance,highlightColor,knockout,quality,shadowColor,strength,type\r\nf2.angle = 45;\r\nf2.blurX = 10;\r\nf2.blurY = 10;\r\nf2.distance = 5;\r\nf2.highlightAlpha = 0.5;\r\nf2.highlightColor = 0xffffff;\r\nf2.knockout = false;\r\nf2.quality = BitmapFilterQuality.HIGH;\r\nf2.shadowAlpha = 0.5;\r\nf2.shadowColor = 0x000000;\r\nf2.strength = 2;\r\nf2.type = BitmapFilterType.INNER;\r\n\/\/.filters = [f0,f1,f2];\r\n\/\/----------------------------\/\/\r\n<\/pre>\n<p>Once extracted from zip move the gd_copy_filter.jsfl and the gskinner_color_martix.jsfl files to the Commands folder in the configuration folder, you may find it here:<\/p>\n<blockquote><p>You can have JSFL scripts available within the Flash authoring environment by storing them in one of several folders within the Configuration folder. By default, the Configuration folder is in the following location:\n<\/p><\/blockquote>\n<ul>\n<li>Windows\u00ae Vista\u2122:<\/li>\n<\/ul>\n<blockquote>\n<ul>\n<li>boot drive\\Users\\username\\Local Settings\\Application Data\\Adobe\\Flash CS4\\language\\Configuration\\<\/li>\n<\/ul>\n<\/blockquote>\n<ul>\n<li>Windows XP:<\/li>\n<\/ul>\n<blockquote>\n<ul>\n<li>boot drive\\Documents and Settings\\username\\Local Settings\\Application Data\\Adobe\\Flash CS4\\language\\Configuration\\<\/li>\n<\/ul>\n<\/blockquote>\n<ul>\n<li>Mac OS\u00ae X:<\/li>\n<\/ul>\n<blockquote>\n<ul>\n<li>Macintosh HD\/Users\/username\/Library\/Application Support\/Adobe\/Flash CS4\/language\/Configuration\/<\/li>\n<\/ul>\n<\/blockquote>\n<p>Once copied the script will appear in the Flash IDE under commands menu, the zip contains also sample file, one more thing, the script comes &#8220;as is&#8221; but I would like to know your feedback,<\/p>\n<p><a href='https:\/\/greladesign.co\/blog\/wp-content\/uploads\/2011\/07\/jsfl_copy_filters.zip'>jsfl_copy_filters<\/a><\/p>\n<p>happy coding<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, working with designers one will always get into a problem of replication IDE based filters via code, it&#8217;s not a pleasant task nor quick as well, but what about if we could actually make it quick and pleasant? Well, &hellip; <a href=\"https:\/\/greladesign.co\/blog\/2011\/07\/21\/jsfl-copy-filters-stack-from-flash-ide-into-actionscript-2-or-3-code\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":""},"categories":[17,9],"tags":[302,107,106,34],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/381"}],"collection":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":15,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":398,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions\/398"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}