Super Simple Script Snippets

I’ve been working on a game.
Some super simple stuff that has come in handy…

//splitting a string every given amount of characters and saving the result to an array

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 count //for character dialogues // DOWNLOAD SOURCE

txt_test.text = “This will clear after a convenient time. Just enough to read it.”;

var timer_prompt:Timer = new Timer(txt_test.length*50, 1);
timer_prompt.addEventListener(TimerEvent.TIMER, clearPrompt);

function clearPrompt(event:TimerEvent):void {
trace(“clearPrompt() called after:” + getTimer() + ” ms.”);
txt_test.text = “”;

//passing a function as a function parameter
//loop through an array, if the array has that element apply a specific function to the movieclip (tile)

var arr_tilename_Walkable:Array = new Array(“up/down”, “left/right”, “t-intersection-1”, “t-intersection-2”, “t-intersection-3”, “t-intersection-4”, “x-intersection”, “l-intersection-1”, “l-intersection-2”, “l-intersection-3”, “l-intersection-4”, “rubble”);
var arr_tilename_Unwalkable:Array = new Array(“cliff_4_2”, “cliff_4_1”, “cliff_4”, “cliff_1_4”, “cliff_3”, “cliff_2”, “cliff_1_3”, “cliff_1_2”, “cliff_1”);
var arr_tilename_Levels:Array = new Array(“suburbs”,”igor”);

function test1(){
trace(“test1() was called, pass the tile some values…”);

function test2(){
trace(“test2() called, pass the tile some other values…”);

//called for applying values to tiles (according to label)…
function loops(func:Function, arr:Array, clip:MovieClip)
for (var k:Number=0; kDOWNLOAD SOURCE

var rex_newlines:RegExp = /(\t|\n|\r)/gi; //strip out newline breaks
txt_aspx.text = txt_aspx.text.replace(rex_newlines,”);

var rex_spaces:RegExp = / /g;//strip out spaces
txt_aspx.text = txt_aspx.text.replace(rex_spaces,”);

It’s shaping up so far…