{"id":2111,"date":"2012-07-27T17:26:33","date_gmt":"2012-07-28T00:26:33","guid":{"rendered":"http:\/\/www.nathalielawhead.com\/candybox\/?p=2111"},"modified":"2012-09-29T10:40:46","modified_gmt":"2012-09-29T17:40:46","slug":"super-simple-script-snippets","status":"publish","type":"post","link":"http:\/\/www.nathalielawhead.com\/candybox\/super-simple-script-snippets","title":{"rendered":"Super Simple Script Snippets"},"content":{"rendered":"<p>I&#8217;ve been working on <a href=\"http:\/\/tetrageddon.com\" target=\"_blank\")>a game<\/a>.<br \/>\nSome super simple stuff that has come in handy&#8230;<br \/>\n<a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\" target=\"_blank\">CLICK HERE FOR THE SOURCE FILES<\/a><\/p>\n<p>&#8212;<\/p>\n<p>\/\/splitting a string every given amount of characters and saving the result to an array<br \/>\n\/\/<a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/string_spliting_byChar.fla\">DOWNLOAD SOURCE<\/a><\/p>\n<p>var arr:Array = new Array();<\/p>\n<p>function str_split(str:String, splitTo:Number)<br \/>\n{<br \/>\n\tvar arr_str:Array = new Array();<br \/>\n\tfor(var i:Number=0; i < str.length; i +=  splitTo){\n\t\tarr_str.push(str.slice(i, i+splitTo));\n\t}\n\treturn(arr_str);\n}\n\nvar str = 'This has been split every 3 characters.';\narr = str_split(str,3);\ntrace(arr);\n\/\/outputs Thi,s h,as ,bee,n s,pli,t e,ver,y 3, ch,ara,cte,rs.\n\n--\n\/\/timing the length of a text field based on its character count\n\/\/for character dialogues\n\/\/ <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/character_dialogue.zip\" target=\"_blank\">DOWNLOAD SOURCE<br \/>\n<a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/character_dialogue.zip\" target=\"_blank\"><\/a><\/p>\n<p>txt_test.text = &#8220;This will clear after a convenient time. Just enough to read it.&#8221;;<\/p>\n<p>var timer_prompt:Timer = new Timer(txt_test.length*50, 1);<br \/>\ntimer_prompt.addEventListener(TimerEvent.TIMER, clearPrompt);<br \/>\ntimer_prompt.start();<\/p>\n<p>function clearPrompt(event:TimerEvent):void {<br \/>\n\ttrace(&#8220;clearPrompt() called after:&#8221; + getTimer() + &#8221; ms.&#8221;);<br \/>\n\ttxt_test.text = &#8220;&#8221;;<br \/>\n}<\/p>\n<p>&#8212;<\/p>\n<p>\/\/passing a function as a function parameter<br \/>\n\/\/loop through an array, if the array has that element apply a specific function to the movieclip (tile)<br \/>\n\/\/ <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/passing_function_parameters_in_eventListener.fla\">DOWNLOAD SOURCE<\/a><\/p>\n<p>var arr_tilename_Walkable:Array = new Array(&#8220;up\/down&#8221;, &#8220;left\/right&#8221;, &#8220;t-intersection-1&#8221;, &#8220;t-intersection-2&#8221;, &#8220;t-intersection-3&#8221;, &#8220;t-intersection-4&#8221;, &#8220;x-intersection&#8221;, &#8220;l-intersection-1&#8221;, &#8220;l-intersection-2&#8221;, &#8220;l-intersection-3&#8221;, &#8220;l-intersection-4&#8221;, &#8220;rubble&#8221;);<br \/>\nvar arr_tilename_Unwalkable:Array = new Array(&#8220;cliff_4_2&#8221;, &#8220;cliff_4_1&#8221;, &#8220;cliff_4&#8221;, &#8220;cliff_1_4&#8221;, &#8220;cliff_3&#8221;, &#8220;cliff_2&#8221;, &#8220;cliff_1_3&#8221;, &#8220;cliff_1_2&#8221;, &#8220;cliff_1&#8221;);<br \/>\nvar arr_tilename_Levels:Array = new Array(&#8220;suburbs&#8221;,&#8221;igor&#8221;);<\/p>\n<p>function test1(){<br \/>\n\ttrace(&#8220;test1() was called, pass the tile some values&#8230;&#8221;);<br \/>\n}<\/p>\n<p>function test2(){<br \/>\n\ttrace(&#8220;test2() called, pass the tile some other values&#8230;&#8221;);<br \/>\n}<\/p>\n<p>\/\/called for applying values to tiles (according to label)&#8230;<br \/>\nfunction loops(func:Function, arr:Array, clip:MovieClip)<br \/>\n{<br \/>\n\tfor (var k:Number=0; k<arr .length; ++k)\n\t{\n\t\tif (clip.currentLabel == arr[k])\n\t\t{\n\t\t\tfunc();\n\t\t}\n\t}\n};\n\nmc_clip.gotoAndStop(\"cliff_4_2\"); \/\/set manually here for demonstration purposes - set dynamically in the engine...\n\nloops(test1, arr_tilename_Levels, mc_clip); \/\/\"cliff_4_2\" is not in the arr_tilename_Levels array, so it will not return anything\nloops(test2, arr_tilename_Unwalkable, mc_clip); \/\/\"cliff_4_2\" is here, and it will call the passed function\n\n\n\/\/striping out newline breaks or spaces from a string\n\/\/a regular expression to clean up alpha numeric data from an aspx page (after parsing) received string (html junk) - for extreme cases...\n\/\/ <a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/remove_newlineBreaks.fla\">DOWNLOAD SOURCE<br \/>\n<a href=\"http:\/\/nathalielawhead.com\/sourcefiles\/Super_Simple_Snippets\/remove_newlineBreaks.fla\" target=\"_blank\"><\/a><\/p>\n<p>var rex_newlines:RegExp = \/(\\t|\\n|\\r)\/gi; \/\/strip out newline breaks<br \/>\ntxt_aspx.text = txt_aspx.text.replace(rex_newlines,&#8221;);<\/p>\n<p>var rex_spaces:RegExp = \/ \/g;\/\/strip out spaces<br \/>\ntxt_aspx.text = txt_aspx.text.replace(rex_spaces,&#8221;);<\/p>\n<p>&#8212;<\/p>\n<p>It&#8217;s shaping up so far&#8230;<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/nathalielawhead.com\/noodles\/supersimplestuff.jpg\" alt=\"\" \/><\/arr><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on a game. Some super simple stuff that has come in handy&#8230; CLICK HERE FOR THE SOURCE FILES &#8212; \/\/splitting a string every given amount of characters and saving the result to an array \/\/DOWNLOAD SOURCE var arr:Array = new Array(); function str_split(str:String, splitTo:Number) { var arr_str:Array = new Array(); for(var i:Number=0; i < str.length; i += splitTo){ arr_str.push(str.slice(i, i+splitTo)); } return(arr_str); } var str = 'This has been split every 3 characters.'; arr = str_split(str,3); trace(arr); \/\/outputs Thi,s h,as ,bee,n s,pli,t e,ver,y 3, ch,ara,cte,rs. -- \/\/timing the length of a text field based on its character&#46;&#46;&#46;\n<\/p>\n","protected":false},"author":1,"featured_media":4522,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","footnotes":"","_links_to":"","_links_to_target":""},"categories":[12],"tags":[],"class_list":["post-2111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-resources"],"_links":{"self":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/2111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/comments?post=2111"}],"version-history":[{"count":25,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/2111\/revisions"}],"predecessor-version":[{"id":2395,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/posts\/2111\/revisions\/2395"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/media\/4522"}],"wp:attachment":[{"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/media?parent=2111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/categories?post=2111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nathalielawhead.com\/candybox\/wp-json\/wp\/v2\/tags?post=2111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}