1 /** 2 * Generic, auxiliary functions 3 * 4 * @author Zeh Fernando 5 * @version 1.0.0 6 */ 7 8 class caurina.transitions.AuxFunctions { 9 10 /** 11 * Gets the R (xx0000) bits from a number 12 * 13 * @param p_num Number Color number (ie, 0xffff00) 14 * @return Number The R value 15 */ 16 public static function numberToR(p_num:Number):Number { 17 // The initial & is meant to crop numbers bigger than 0xffffff 18 return (p_num & 0xff0000) >> 16; 19 } 20 21 /** 22 * Gets the G (00xx00) bits from a number 23 * 24 * @param p_num Number Color number (ie, 0xffff00) 25 * @return Number The G value 26 */ 27 public static function numberToG(p_num:Number):Number { 28 return (p_num & 0xff00) >> 8; 29 } 30 31 /** 32 * Gets the B (0000xx) bits from a number 33 * 34 * @param p_num Number Color number (ie, 0xffff00) 35 * @return Number The B value 36 */ 37 public static function numberToB(p_num:Number):Number { 38 return (p_num & 0xff); 39 } 40 41 /** 42 * Checks whether a string is on an array 43 * 44 * @param p_string String String to search for 45 * @param p_array Array Array to be searched 46 * @return Boolean Whether the array contains the string or not 47 */ 48 public static function isInArray(p_string:String, p_array:Array):Boolean { 49 var l:Number = p_array.length; 50 for (var i:Number = 0; i < l; i++) { 51 if (p_array[i] == p_string) return true; 52 } 53 return false; 54 } 55 56 /** 57 * Returns the number of properties an object has 58 * 59 * @param p_object Object Target object with a number of properties 60 * @return Number Number of total properties the object has 61 */ 62 public static function getObjectLength(p_object:Object):Number { 63 var totalProperties:Number = 0; 64 for (var pName:String in p_object) totalProperties ++; 65 return totalProperties; 66 } 67 68 /* Takes a variable number of objects as parameters and "adds" their properties, from left to right. If a latter object defines a property as null, it will be removed from the final object 69 * @param args Object(s) A variable number of objects 70 * @return Object An object with the sum of all paremeters added as properties. 71 */ 72 public static function concatObjects(/*objects to concat*/) : Object{ 73 var finalObject : Object = {}; 74 var currentObject : Object; 75 for (var i : Number = 0; i < arguments.length; i++){ 76 currentObject = arguments[i]; 77 for (var prop : String in currentObject){ 78 if (currentObject[prop] == null){ 79 // delete in case is null 80 delete finalObject[prop]; 81 }else{ 82 finalObject[prop] = currentObject[prop] 83 } 84 } 85 } 86 return finalObject; 87 } 88 } 89