source: code/Website/open-flash-chart/caurina/transitions/AuxFunctions.as@ 7937

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