{"id":449,"date":"2009-12-11T14:41:44","date_gmt":"2009-12-11T21:41:44","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2508"},"modified":"2009-12-11T14:41:44","modified_gmt":"2009-12-11T21:41:44","slug":"graphics-class-and-twitter","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=449","title":{"rendered":"Graphics Class and Twitter"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n&#x5B;SWF(width = 700, height=700, frameRate=12)]\r\nvar cmds:Array = &#x5B;];\r\n\r\nvar loader:URLLoader = new URLLoader();\r\nvar req:URLRequest = new URLRequest(&quot;http:\/\/search.twitter.com\/search.atom&quot;);\r\nvar vars:URLVariables = new URLVariables();\r\nvars.q = &quot;#asgraph&quot;;\r\n\/\/ results per page\r\nvars.rpp = &quot;100&quot;;\r\nvars.page = 1;\r\n\r\nreq.data = vars;\r\nreq.method = URLRequestMethod.GET;\r\n\r\nloader.addEventListener(Event.COMPLETE, onLoaded);\r\nloader.load(req);\r\n\r\nvar txt:TextField = TextField(addChild(new TextField()));\r\ntxt.defaultTextFormat = new TextFormat(&quot;_sans&quot;, 12);\r\nwith (txt){ x=10, y=10, autoSize=&quot;left&quot;; }\r\ntxt.htmlText = &quot;loading...&quot;;\r\n\r\nfunction onLoaded(evt:Event):void{\r\n       removeChild(txt);\r\n   var searchData:XML = new XML(loader.data);\r\n   var atom:Namespace = searchData.namespace(&quot;&quot;);\r\n\r\n   var leng:int = searchData.atom::entry.length() -1;\r\n  for (var i:int = leng; i&gt;=0; i--){\r\n       var cmd:String =\r\nsearchData.atom::entry&#x5B;i].atom::title.toString().replace(\/#asgraph\/g,\r\n&quot;&quot;);\r\n      \/\/ added this to ignore words starting with @\r\n      cmd = cmd.replace(\/@(w+)\/g, &quot;&quot;);\r\n       cmds.push(cmd);\r\n   }\r\n\r\n       var time:Timer = new Timer(100, cmds.length);\r\n       time.addEventListener(TimerEvent.TIMER, onTick);\r\n   time.start();\r\n}\r\nfunction onTick(evt:TimerEvent):void{\r\n       render(parseFunctions(cmds&#x5B;evt.target.currentCount - 1]));\r\n       graphics.endFill();\r\n       graphics.lineStyle();\r\n}\r\n\r\n\/\/ parse and run Graphics class commands\r\nfunction parseFunctions(dat:String):Array{\r\n   var a:Array = dat.split(&quot;;&quot;) ;\r\n   for (var i:int = 0; i&lt;a.length-1; i++){\r\n       a&#x5B;i] = a&#x5B;i].split(\/()|(|)\/g);\r\n       var f:String = a&#x5B;i]&#x5B;0] = a&#x5B;i]&#x5B;0].replace(\/s\/g,&quot;&quot;);\r\n       a&#x5B;i] = a&#x5B;i].splice(0, a&#x5B;i].length - 1);\r\n       if (a&#x5B;i].length&gt; 1){\r\n        a&#x5B;i] = a&#x5B;i]&#x5B;1].split(&quot;,&quot;);\r\n        a&#x5B;i].unshift(f);\r\n       }\r\n   }\r\n   return a.splice(0,a.length - 1);\r\n}\r\nfunction render(p:Array):void {\r\n   for (var i:int = 0; i&lt;p.length; i++) {\r\n       try{\r\n       graphics&#x5B;p&#x5B;i]&#x5B;0]].apply(graphics,p&#x5B;i].splice(1));\r\n       }catch(e:Error){};\r\n   }\r\n}\r\n<\/pre>\n<p>This is a simple idea I had awhile back&#8230; This snippet searches twitter for the #asgraph hashtag and if it finds standard Graphics class method calls it renders them.<\/p>\n<p>So if you tweet something likethis :<\/p>\n<pre>\r\n#asgraph beginFill(0xFF); drawCircle(200,200,10); \r\n<\/pre>\n<p>it will get rendered into the below swf (you&#8217;ll need to refresh to see your tweet get rendered):<\/p>\n<p>[SWF]https:\/\/actionsnippet.com\/wp-content\/asgraph.swf, 700, 700[\/SWF]<\/p>\n<p><a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/wp-content\/asgraph.swf\">Here is a direct link to the swf<\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/wp-content\\\/asgraph.swf&quot;,&quot;title&quot;:&quot;asgraph&quot;,&quot;width&quot;:700,&quot;height&quot;:700,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: asgraph<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#x5B;SWF(width = 700, height=700, frameRate=12)] var cmds:Array = &#x5B;]; var loader:URLLoader = new URLLoader(); var req:URLRequest = new URLRequest(&quot;http:\/\/search.twitter.com\/search.atom&quot;); var vars:URLVariables = new URLVariables(); vars.q = &quot;#asgraph&quot;; \/\/ results per page vars.rpp = &quot;100&quot;; vars.page = 1; req.data = vars; req.method = URLRequestMethod.GET; loader.addEventListener(Event.COMPLETE, onLoaded); loader.load(req); var txt:TextField = TextField(addChild(new TextField())); txt.defaultTextFormat = new TextFormat(&quot;_sans&quot;, [&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,33],"tags":[3,14,4],"class_list":["post-449","post","type-post","status-publish","format-standard","hentry","category-external-data","category-graphics","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/449","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=449"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/449\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}