{"id":139,"date":"2008-12-30T00:00:01","date_gmt":"2008-12-30T07:00:01","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=439"},"modified":"2008-12-30T00:00:01","modified_gmt":"2008-12-30T07:00:01","slug":"e4x-and-actionscript-variables","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=139","title":{"rendered":"E4X and ActionScript Variables"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar backgroundColor:uint = 0xEFEFEF;\r\nvar borderColor:uint = 0xFF0000;\r\nvar buttonOverColor:uint = 0x0000FF;\r\nvar buttonOutColor:uint = 0x00CCCC;\r\n\r\nvar uiColors:XML = &lt;ui&gt;\r\n\t&lt;default color=&quot;0xCCCCCC&quot; \/&gt;\r\n\t&lt;background color = { backgroundColor } \/&gt;\r\n\t\r\n\t&lt;!-- note hexidecimal formatting code --&gt;\r\n\t&lt;border color={ (&quot;0x&quot; + borderColor.toString(16)) } \/&gt;\r\n\t\r\n\t&lt;button overColor={ buttonOverColor} outColor={ buttonOutColor } \/&gt;\r\n&lt;\/ui&gt;\r\n\r\ntrace(uiColors.toXMLString());\r\n\r\n\/*outputs:\r\n&lt;ui&gt;\r\n  &lt;default color=&quot;0xCCCCCC&quot;\/&gt;\r\n  &lt;background color=&quot;15724527&quot;\/&gt;\r\n  &lt;border color=&quot;0xff0000&quot;\/&gt;\r\n  &lt;button overColor=&quot;255&quot; outColor=&quot;52428&quot;\/&gt;\r\n&lt;\/ui&gt;\r\n*\/\r\n<\/pre>\n<p>The first time I needed to use an ActionScript variable within inline XML I was stumped. I couldn&#8217;t figure it out and I wasn&#8217;t able to easily find it on google. I eventually found it somewhere (don&#8217;t remember where&#8230; possibly hidden away in the docs). <\/p>\n<p>Now a search for &#8220;insert actionscript variables into e4x&#8221; on google gives plenty of results. But I figure it&#8217;s worth a post.<\/p>\n<p>I use actionscript to generate XML all the time so this comes in handy. I also store color values in automatically generated XML all the time. If I&#8217;m feeling organized I&#8217;ll use something like what you see on line 10:<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&lt;border color={ (&quot;0x&quot; + borderColor.toString(16)) } \/&gt;\r\n<\/pre>\n<p>If you look at the output you&#8217;ll see this formats the uint so that it&#8217;s readable as a hex number. By default (as you can see in the output) uints will show up in decimal notation. This really doesn&#8217;t make any difference if you don&#8217;t care about XML readability &#8230; or if you just don&#8217;t care about the readability of the colors stored in your XML&#8230;.. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>var backgroundColor:uint = 0xEFEFEF; var borderColor:uint = 0xFF0000; var buttonOverColor:uint = 0x0000FF; var buttonOutColor:uint = 0x00CCCC; var uiColors:XML = &lt;ui&gt; &lt;default color=&quot;0xCCCCCC&quot; \/&gt; &lt;background color = { backgroundColor } \/&gt; &lt;!&#8211; note hexidecimal formatting code &#8211;&gt; &lt;border color={ (&quot;0x&quot; + borderColor.toString(16)) } \/&gt; &lt;button overColor={ buttonOverColor} outColor={ buttonOutColor } \/&gt; &lt;\/ui&gt; trace(uiColors.toXMLString()); \/*outputs: &lt;ui&gt; &lt;default [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59,68,34],"tags":[3,106,4,92],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-color","category-variables","category-xml","tag-actionscript","tag-e4x","tag-flash","tag-xml"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}