AuxFunctions.as 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package caurina.transitions {
  2. /**
  3. * Generic, auxiliary functions
  4. *
  5. * @author Zeh Fernando
  6. * @version 1.0.0
  7. * @private
  8. */
  9. public class AuxFunctions {
  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. * Gets the G (00xx00) bits from a number
  22. *
  23. * @param p_num Number Color number (ie, 0xffff00)
  24. * @return Number The G value
  25. */
  26. public static function numberToG(p_num:Number):Number {
  27. return (p_num & 0xff00) >> 8;
  28. }
  29. /**
  30. * Gets the B (0000xx) bits from a number
  31. *
  32. * @param p_num Number Color number (ie, 0xffff00)
  33. * @return Number The B value
  34. */
  35. public static function numberToB(p_num:Number):Number {
  36. return (p_num & 0xff);
  37. }
  38. /**
  39. * Returns the number of properties an object has
  40. *
  41. * @param p_object Object Target object with a number of properties
  42. * @return Number Number of total properties the object has
  43. */
  44. public static function getObjectLength(p_object:Object):uint {
  45. var totalProperties:uint = 0;
  46. for (var pName:String in p_object) totalProperties ++;
  47. return totalProperties;
  48. }
  49. /* 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
  50. * @param args Object(s) A variable number of objects
  51. * @return Object An object with the sum of all paremeters added as properties.
  52. */
  53. public static function concatObjects(...args) : Object{
  54. var finalObject : Object = {};
  55. var currentObject : Object;
  56. for (var i : int = 0; i < args.length; i++){
  57. currentObject = args[i];
  58. for (var prop : String in currentObject){
  59. if (currentObject[prop] == null){
  60. // delete in case is null
  61. delete finalObject[prop];
  62. }else{
  63. finalObject[prop] = currentObject[prop];
  64. }
  65. }
  66. }
  67. return finalObject;
  68. }
  69. }
  70. }