source: trunk/fl5/src/com/longtailvideo/jwplayer/utils/TypeChecker.as @ 984

Revision 984, 2.1 KB checked in by pablo, 3 years ago (diff)
  • Allow PNG skin settings to define font face, weight, color, size and style (697)
  • Ability to do the same for playlist item text, with an additional "active" color (798)
  • Additional "playlist.backgroundcolor" setting, which allows XML skins to define a background color behind the playlist items (885)
Line 
1package com.longtailvideo.jwplayer.utils {
2        import com.longtailvideo.jwplayer.model.Color;
3       
4        import flash.utils.describeType;
5
6        public class TypeChecker {
7               
8                public static function getType(object:Object, property:String):String {
9                        var description:XML = describeType(object);
10                        var type:String;
11                       
12                        if ((description.accessor as XMLList).length()) {
13                                type = description.accessor.(@name == property).@type;
14                        } else {
15                                type = description.variable.(@name == property).@type;
16                        }
17                        return type.replace(/(.+::)(.*)/,"$2");
18                }
19
20                public static function guessType(value:String):String {
21                        var bools:Array = ["true", "false", "t", "f"];
22                        if (bools.indexOf(value.toLowerCase().replace(" ","")) >= 0) {
23                                return "Boolean";
24                        } else if ( value.search(/^(#|0x)[0-9a-fA-F]{3,6}/) >= 0 ) {
25                                return "Color";
26                        } else if (!isNaN(Number(value)) ) {
27                                return "Number";
28                        } else {
29                                return "String";
30                        }
31                }
32               
33                public static function fromString(value:String, type:String=null):* {
34                        if (type == null)
35                                type = guessType(value);
36
37                        switch(type.toLowerCase()) {
38                                case "color":
39                                        if (value.length > 0) {
40                                                return new Color(stringToColor(value));
41                                        } else return null;
42                                case "number":
43                                        return Number(value);
44                                case "boolean":
45                                        if (value.toLowerCase() == "true") return true;
46                                        else if (value == "1") return true;
47                                        else return false;
48                        }
49                        return value;
50                }
51               
52                public static function stringToColor(value:String):uint {
53                        switch(value.toLowerCase()) {
54                                case "blue": return 0x0000FF; break;
55                                case "green": return 0x00FF00; break;
56                                case "red": return 0xFF0000; break;
57                                case "cyan": return 0x00FFFF; break;
58                                case "magenta": return 0xFF00FF; break;
59                                case "yellow": return 0xFFFF00; break;
60                                case "black": return 0x000000; break;
61                                case "white": return 0xFFFFFF; break;
62                                default:
63                                        value = value.replace(/(#|0x)?([0-9A-F]{3,6})$/gi, "$2");
64                                        if (value.length == 3)
65                                                value = value.charAt(0) + value.charAt(0) + value.charAt(1) + value.charAt(1) + value.charAt(2) + value.charAt(2);
66                                        return uint("0x" + value);
67                                        break;
68                        }
69                       
70                        return 0x000000;
71                }
72
73        }
74       
75}
Note: See TracBrowser for help on using the repository browser.