{"id":517,"date":"2010-06-04T07:56:41","date_gmt":"2010-06-04T14:56:41","guid":{"rendered":"https:\/\/actionsnippet.com\/?p=2936"},"modified":"2010-06-04T07:56:41","modified_gmt":"2010-06-04T14:56:41","slug":"fill-in-the-blank","status":"publish","type":"post","link":"https:\/\/actionsnippet.com\/?p=517","title":{"rendered":"Fill in the Blank"},"content":{"rendered":"<pre class=\"brush: as3; title: ; notranslate\" title=\"\">\r\n\r\nvar story:String = &quot;Fill in the _____.&quot;;\r\n\r\n\r\nvar txt:TextField = new TextField();\r\ntxt.defaultTextFormat = new TextFormat(&quot;Georgia&quot;, 20);\r\ntxt.width = stage.stageWidth;\r\ntxt.multiline = true;\r\ntxt.wordWrap = true;\r\ntxt.text = story;\r\naddChild(txt);\r\n\r\nvar alph:Array = &quot;abcdefghijklmnopqrstuvwxyz&quot;.split(&quot;&quot;);\r\nvar keys:Object = {};\r\nfor (var i:int = 0; i&lt;alph.length; i++){\r\n\tkeys&#x5B;65 + i] = alph&#x5B;i];\r\n}\r\nstage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed);\r\nfunction onKeyPressed(evt:KeyboardEvent):void{\r\n\t \r\n\tif (evt.keyCode == Keyboard.ENTER){\r\n\t\tstory = &quot;Fill in the _____.&quot;;\r\n\t\ttxt.text = story;\r\n\t}\r\n\t\r\n\tfor (var i:int = 0; i&lt;story.length; i++){\r\n\t\tif (story.charAt(i) == &quot;_&quot;){\r\n\t\t\tvar head:String = story.substr(0, i);\r\n\t\t\tvar tail:String = story.substr(i + 1);\r\n\t\t\tvar letter:String = keys&#x5B;evt.keyCode];\r\n\t\t\tif (!letter) return;\r\n\t\t\tstory = head + letter + tail;\r\n\t\t\t\r\n\t\t\ttxt.text = story;\r\n\t\t\t\r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>I needed to do a fill in the blank for a personal project that I&#8217;m working on and this is what I came up with. Have a look at the swf here:<\/p>\n<p>(you need to click first so you can type with the keyboard):<br \/>\n<a data-asruffle-linked=\"true\" href=\"https:\/\/actionsnippet.com\/swfs\/text_entry.html\" target=\"blank\">Fill in the blank<\/a> <span class=\"asruffle-link\" data-swf=\"{&quot;url&quot;:&quot;https:\\\/\\\/actionsnippet.com\\\/swfs\\\/text_entry.swf&quot;,&quot;title&quot;:&quot;text entry&quot;,&quot;width&quot;:800,&quot;height&quot;:600,&quot;missing&quot;:false,&quot;allowScriptAccess&quot;:false,&quot;backgroundColor&quot;:&quot;#ffffff&quot;}\"><button type=\"button\" hidden aria-expanded=\"false\">Play demo<span class=\"screen-reader-text\">: text entry<\/span><\/button><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>var story:String = &quot;Fill in the _____.&quot;; var txt:TextField = new TextField(); txt.defaultTextFormat = new TextFormat(&quot;Georgia&quot;, 20); txt.width = stage.stageWidth; txt.multiline = true; txt.wordWrap = true; txt.text = story; addChild(txt); var alph:Array = &quot;abcdefghijklmnopqrstuvwxyz&quot;.split(&quot;&quot;); var keys:Object = {}; for (var i:int = 0; i&lt;alph.length; i++){ keys&#x5B;65 + i] = alph&#x5B;i]; } stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyPressed); function onKeyPressed(evt:KeyboardEvent):void{ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[156,98],"tags":[3,14,4],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-textfield","category-ui","tag-actionscript","tag-as3","tag-flash"],"_links":{"self":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/517","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=517"}],"version-history":[{"count":0,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=\/wp\/v2\/posts\/517\/revisions"}],"wp:attachment":[{"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/actionsnippet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}