{"id":265,"date":"2011-01-22T03:16:09","date_gmt":"2011-01-22T03:16:09","guid":{"rendered":"https:\/\/greladesign.co\/blog\/?p=265"},"modified":"2011-07-29T14:26:55","modified_gmt":"2011-07-29T13:26:55","slug":"stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style","status":"publish","type":"post","link":"https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/","title":{"rendered":"StyleSheet&#8217;s method getStyle doesn&#8217;t return null for non-existing style"},"content":{"rendered":"<p>I have just learned that <em>getStyle()<\/em> method of <em>flash.text.StyleSheet<\/em> class doesn&#8217;t return null value when requested style doesn&#8217;t exists. <a href=\"http:\/\/help.adobe.com\/en_US\/FlashPlatform\/reference\/actionscript\/3\/flash\/text\/StyleSheet.html#getStyle%28%29\">Documentation<\/a> states that it should, but in fact it returns empty object. Which could be fine for tests but you could have a style with empty declaration block which would create false positive result. This error appears to be for some time, check screen grabs from different players starting from fp9.<br \/>\n<!--more--><br \/>\n<div id='gallery-1' class='gallery galleryid-265 gallery-columns-2 gallery-size-thumbnail'><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/fp9\/'><img width=\"150\" height=\"150\" src=\"https:\/\/greladesign.co\/blog\/wp-content\/uploads\/2011\/01\/fp9-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"FP 9.0.124.0\" loading=\"lazy\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/fp10-1-52-14\/'><img width=\"150\" height=\"150\" src=\"https:\/\/greladesign.co\/blog\/wp-content\/uploads\/2011\/01\/fp10.1.52.14-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"FP 10.1.52.14\" loading=\"lazy\" \/><\/a>\n\t\t\t<\/dt><\/dl><br style=\"clear: both\" \/><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/fp10-1-85-3\/'><img width=\"150\" height=\"150\" src=\"https:\/\/greladesign.co\/blog\/wp-content\/uploads\/2011\/01\/fp10.1.85.3-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"FP 10.1.85.3\" loading=\"lazy\" \/><\/a>\n\t\t\t<\/dt><\/dl><dl class='gallery-item'>\n\t\t\t<dt class='gallery-icon portrait'>\n\t\t\t\t<a href='https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/fp10\/'><img width=\"150\" height=\"150\" src=\"https:\/\/greladesign.co\/blog\/wp-content\/uploads\/2011\/01\/fp10-150x150.png\" class=\"attachment-thumbnail size-thumbnail\" alt=\"FP 10.0.12.36\" loading=\"lazy\" \/><\/a>\n\t\t\t<\/dt><\/dl><br style=\"clear: both\" \/>\n\t\t<\/div>\n<\/p>\n<p>The solution is to extend StyleSheet class and override the getStyle method, then we can use the <em>styleNames<\/em> property to check if it contains requested style, if not return null otherwise call super method.<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\npackage\r\n{\r\n\timport flash.text.StyleSheet;\r\n\t\r\n\t\/**\r\n\t * Fixes issue with getStyle method returning empty object for non-existing style.\r\n\t *\r\n\t * @author Lukasz 'Severiaan' Grela\r\n\t *\/\r\n\tpublic class FixedStyleSheet extends StyleSheet\r\n\t{\r\n\t\t\/**\r\n\t\t * Variable storing the style name used in the test function\r\n\t\t *\/\r\n\t\tprotected var m_sStyleNameCondition:String;\r\n\t\tpublic function FixedStyleSheet()\r\n\t\t{\r\n\t\t\tsuper();\r\n\t\t\t\r\n\t\t}\r\n\t\t\/**\r\n\t\t * Patch to fix issue with not returning null value for non-existing styles\r\n\t\t * @param\tstyleName\r\n\t\t * @return\r\n\t\t *\/\r\n\t\toverride public function getStyle(styleName:String):Object\r\n\t\t{\r\n\t\t\tm_sStyleNameCondition = styleName;\r\n\t\t\tif (styleNames.some(searchForStyleName, null))\r\n\t\t\t{\r\n\t\t\t\tvar o:Object = super.getStyle(styleName);\r\n\t\t\t\treturn o;\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn null;\r\n\t\t}\r\n\t\t\r\n\t\tprotected function searchForStyleName(item:*,index:int,list:Array):Boolean\r\n\t\t{\r\n\t\t\treturn item == m_sStyleNameCondition;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>Edit:<br \/>\nI have recently found that this issue was reported in JIRA, give your vote <a href=\"http:\/\/bugs.adobe.com\/jira\/browse\/ASL-198\" title=\"getStyle bug\">here<\/a> and <a href=\"http:\/\/bugs.adobe.com\/jira\/browse\/FP-113\" title=\"getStyle bug 2\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have just learned that getStyle() method of flash.text.StyleSheet class doesn&#8217;t return null value when requested style doesn&#8217;t exists. Documentation states that it should, but in fact it returns empty object. Which could be fine for tests but you could &hellip; <a href=\"https:\/\/greladesign.co\/blog\/2011\/01\/22\/stylesheets-method-getstyle-doesnt-return-null-for-non-existing-style\/\">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,72,9],"tags":[12,108,74,301,109,75,76,73],"_links":{"self":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/265"}],"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=265"}],"version-history":[{"count":7,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/posts\/265\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/media?parent=265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/categories?post=265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/greladesign.co\/blog\/wp-json\/wp\/v2\/tags?post=265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}