{"id":135,"date":"2008-12-26T09:13:42","date_gmt":"2008-12-26T16:13:42","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=426"},"modified":"2008-12-26T09:13:42","modified_gmt":"2008-12-26T16:13:42","slug":"dynamic-vars-dictionary","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=135","title":{"rendered":"Dynamic Vars Dictionary"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\r\nvar vars:Dictionary = new Dictionary();\r\n\r\nvar sp:Sprite = new Sprite();\r\n\r\n\/\/ associate variables with a sprite (or any non-dynamic class)\r\nvars&#x5B;sp] = {posX:100, posY:100, velX:1, velY:1};\r\n\r\n\/\/ read\r\ntrace(vars&#x5B;sp].posX);\r\n\r\n<\/pre>\n<p>I&#8217;ve heard people mention that they wish the sprite class were dynamic&#8230; meaning they wish they could add methods and properties to a Sprite instance at runtime. There&#8217;s no way I know of to do this, however&#8230; the dictionary class can be used to associate variables with any non-dynamic class instance&#8230; as it does in this the above example.<\/p>\n<p>The dictionary class is similar to an associative array except that instead of using strings for keys, dictionaries use object instances.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>var vars:Dictionary = new Dictionary(); var sp:Sprite = new Sprite(); \/\/ associate variables with a sprite (or any non-dynamic class) vars&#x5B;sp] = {posX:100, posY:100, velX:1, velY:1}; \/\/ read trace(vars&#x5B;sp].posX); I&#8217;ve heard people mention that they wish the sprite class were dynamic&#8230; meaning they wish they could add methods and properties to a Sprite instance at [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,104,9],"tags":[3,4],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-arrays","category-dictionary","category-dynamic","tag-actionscript","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/135","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=135"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/135\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}