/****************************************** * @author Maria A. Zamora * @company Digitec Interactive Inc. * @version 0.1 * @date 12/14/2010 * * These are helper functions for the CEE application * CS5 version of com.digitec.cee.HelperFunctions * *******************************************/ package com.digitec.cee { import flash.text.TextFormat; public class HelperFunctions { /*********************************************************************************************************** * FUNCTIONS: TO EXTRACT FUNCTION NAME OF THE STRING PASSED AS ARGUMENT * RETURN: ARRAY WITH 1ST ELEMENT, ARRAY[0] = NAME OF FUNCTION * AND ARRAY[1] IS A STRING OF ARGUMENTS **********************************************************************************************************/ public static function extractFunctionName(str:String):Array { //var str:String = "function=viewLesson, args=15852, 15853"; var functionArray:Array = new Array(); var match:RegExp =/function=.+?,/ix; var argumentsStr:String = str.replace( match, "" ); var arr:Array = str.match(match) ; //output: function=viewLesson, var match2:RegExp =/function=?/ix; //match: function= var fname:String = arr[0].replace(match2, ""); //replace match2 (function=) for nothing //output: viewLesson, fname = fname.replace("=", ""); //eliminate any comma fname = fname.replace(" ", ""); //eliminate anywhite space fname = fname.replace(",", ""); //replace function= for nothing //output: viewLesson, functionArray[0] = fname; functionArray[1] = argumentsStr; return functionArray; } /*********************************************************************************** * FUNCTION: EXTRACT NUMBER ARRAY OF STRING "36, 49, 45, 25" ***********************************************************************************/ public static function getNumberArrayFromString(str:String):Array { var results:Array = []; trace("str "+str); trace(str.indexOf("," , 0 )); if(str.indexOf("," , 0 ) == -1 ){ results[0] = str; }else{ var re:RegExp = /,/g; results = str.split(re); } return results; } /*********************************************************************************** * FUNCTION: EXTRACT ARRAY OF STRING Based in a character ***********************************************************************************/ public static function getArrayCommaDelimeter(str:String):Array { var results:Array; if( str.indexOf("," , 0 ) == -1 ){ results[0] = str; }else{ var re:RegExp = /,/g; results = str.split(re); } return results; } /*********************************************************************************** * FUNCTION: EXTRACT STRING ARRAY OF STRING Teacher - Lesson 11,15898|Student - Lesson 11,66190|Student - Exercise 11.1,66191|Student - Exercise 11.2,66192 ***********************************************************************************/ public static function getArrayAltVersion(str:String):Array { var results:Array; if(str.indexOf("\|" , 0 ) == -1 ){ results[0] = str; }else{ var re:RegExp = /\|/g; results = str.split(re); } return results; } /*********************************************************************************** * Function getInstanceNumber(String):int -Return the instace number from mcName_num ***********************************************************************************/ public static function getInstanceNumber(str:String):int { var num:int=0; var index_:Number = str.lastIndexOf("_"); var endindex:Number = str.length; if( (index_ >= 0)&& (str.length > 0) ){ num = int( str.substring((index_+1), endindex ) ); } return num; } /*********************************************************************************** * Force any object that have TextFormat to make text Bold ***********************************************************************************/ public static function forceBoldText(obj:Object):void { var popFormat:TextFormat = obj.getTextFormat(); popFormat.bold = true; obj.setTextFormat(popFormat); } /*********************************************************************************** * GET ANY RANDOM NUMBER FROM 1- 100 ***********************************************************************************/ public function getRandomNumber():uint { return Math.round(Math.random()*100); } } }