{"id":421,"date":"2009-10-03T09:22:04","date_gmt":"2009-10-03T16:22:04","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2281"},"modified":"2009-10-03T09:22:04","modified_gmt":"2009-10-03T16:22:04","slug":"actionscript-eval-well-not-really","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=421","title":{"rendered":"ActionScript Eval (well, not really)"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\nvar txt:TextField = TextField(addChild(new TextField()));\r\ntxt.autoSize = TextFieldAutoSize.LEFT;\r\n\r\nvar myVar:Number = 100;\r\n\/\/ works as an expression parser\r\ntxt.text = js(&quot;return (&quot; + myVar + &quot; * 2 + 10) \/ 2&quot;);\r\ntxt.appendText(&quot;nn&quot;);\r\n\r\n\/\/ parses javascript\r\ntxt.appendText(js(&quot;var a = &#x5B;]; for (var i = 0; i&lt;10; i++){ a.push(i) } return a;&quot;));\r\n\r\nfunction js( data:String ):*{\r\n   var res:*= ExternalInterface.call(&quot;function(){&quot; + data + &quot;}&quot;);\r\n   return (res == null) ? &quot;null&quot; : res;\r\n}\r\n<\/pre>\n<p>This one made my day &#8211; CAN&#8217;T believe I never thought of it before&#8230; haven&#8217;t done any speed tests yet&#8230; but it shows how to use ExternalInterface.call to parse math expressions and javascript code. This will only work when the swf is shown in an html page of course&#8230; so if your in flash cmd+f12&#8230;<\/p>\n<p>I got the idea from <a href=\"http:\/\/cookbooks.adobe.com\/post_Fast__light__simple_JSON_decoding-16271.html\" target=\"blank\">this code snippet&#8230;<\/a> which actually has an error in it&#8230; the decode() function should not return void&#8230; I found that snippet thanks to <a href=\"http:\/\/twitter.com\/makc3d\/statuses\/4577019947\" target=\"blank\">this tweet by makc3d.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var txt:TextField = TextField(addChild(new TextField())); txt.autoSize = TextFieldAutoSize.LEFT; var myVar:Number = 100; \/\/ works as an expression parser txt.text = js(&quot;return (&quot; + myVar + &quot; * 2 + 10) \/ 2&quot;); txt.appendText(&quot;nn&quot;); \/\/ parses javascript txt.appendText(js(&quot;var a = &#x5B;]; for (var i = 0; i&lt;10; i++){ a.push(i) } return a;&quot;)); function js( data:String ):*{ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[88,17,121,94,20,21],"tags":[3,4,134],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-external-data","category-functions","category-math","category-misc","category-string-manipulation","category-strings","tag-actionscript","tag-flash","tag-javascript"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/421","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=421"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/421\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}