{"id":340,"date":"2011-03-09T13:46:08","date_gmt":"2011-03-09T18:46:08","guid":{"rendered":"http:\/\/www.thaylin.com\/blog\/?p=340"},"modified":"2011-03-09T13:48:25","modified_gmt":"2011-03-09T18:48:25","slug":"setting-properties-at-runtime-from-xml-or-css","status":"publish","type":"post","link":"https:\/\/www.thaylin.com\/blog\/2011\/03\/09\/setting-properties-at-runtime-from-xml-or-css\/","title":{"rendered":"setting properties at runtime from xml or css"},"content":{"rendered":"<p>Mainly this is just a post to remind myself in later times about this code snippet but basically this will work with any class with accessible variables.<\/p>\n<p>Take an xml node such as<\/p>\n<pre lang=\"xml\" colla=\"+\">\r\n<class id=\"myClass\" color=\"#FF0000\" isActive=\"false\"\/>\r\n<\/pre>\n<p>You can use this snippet to parse through those attributes to set all of your variables for you assuming they exist in your class.<\/p>\n<pre lang=\"actionscript\" line=\"1\" colla=\"+\">\r\npublic function setPropertiesFromXML(xmlNode:XML):void\r\n{\r\n\tfor each (var obj:XML in xmlNode.@*)\r\n\t{\r\n\t\t\/\/check for hex color before setting\r\n\t\tvar strValue:String = obj.toString().replace('#', '0x');\r\n\t\tif( hasOwnProperty(obj.name()) ) this[obj.name().toString()] = (strValue==\"false\") ? false : strValue;\r\n\t}\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Mainly this is just a post to remind myself in later times about this code snippet but basically this will work with any class with accessible variables. Take an xml node such as You can use this snippet to parse through those attributes to set all of your variables for you assuming they exist in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,6,8,27],"tags":[],"_links":{"self":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/340"}],"collection":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/comments?post=340"}],"version-history":[{"count":6,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions"}],"predecessor-version":[{"id":346,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/340\/revisions\/346"}],"wp:attachment":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/media?parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/categories?post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/tags?post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}