1
9
10 import caurina.transitions.Tweener;
11 import caurina.transitions.AuxFunctions;
12
13 class caurina.transitions.properties.TextShortcuts {
14
15
18 public function TextShortcuts () {
19 trace ("This is an static class and should not be instantiated.")
20 }
21
22
25 public static function init():Void {
26
27 Tweener.registerSpecialProperty("_text", _text_get, _text_set, undefined, _text_preProcess);
28
29
30
31 Tweener.registerSpecialPropertySplitter("_text_color", _generic_color_splitter, ["_text_color_r", "_text_color_g", "_text_color_b"]);
32 Tweener.registerSpecialProperty("_text_color_r", _textFormat_property_get, _textFormat_property_set, ["color", true, "r"]);
33 Tweener.registerSpecialProperty("_text_color_g", _textFormat_property_get, _textFormat_property_set, ["color", true, "g"]);
34 Tweener.registerSpecialProperty("_text_color_b", _textFormat_property_get, _textFormat_property_set, ["color", true, "b"]);
35 Tweener.registerSpecialProperty("_text_indent", _textFormat_property_get, _textFormat_property_set, ["indent"]);
36 Tweener.registerSpecialProperty("_text_leading", _textFormat_property_get, _textFormat_property_set, ["leading"]);
37 Tweener.registerSpecialProperty("_text_leftMargin", _textFormat_property_get, _textFormat_property_set, ["leftMargin"]);
38 Tweener.registerSpecialProperty("_text_letterSpacing", _textFormat_property_get, _textFormat_property_set, ["letterSpacing"]);
39 Tweener.registerSpecialProperty("_text_rightMargin", _textFormat_property_get, _textFormat_property_set, ["rightMargin"]);
40 Tweener.registerSpecialProperty("_text_size", _textFormat_property_get, _textFormat_property_set, ["size"]);
41
42 }
43
44
45
46
47
48
49
50
51
57 public static function _text_get (p_obj:Object, p_parameters:Array, p_extra:Object):Number {
58
59 return -p_obj.text.length;
60 }
61
62
68 public static function _text_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object):Void {
69
70
71 if (p_value < 0) {
72
73 p_obj.text = p_extra.oldText.substr(0, -Math.round(p_value));
74 } else {
75
76 p_obj.text = p_extra.newText.substr(0, Math.round(p_value));
77 }
78 }
79
80 public static function _text_preProcess (p_obj:Object, p_parameters:Array, p_originalValueComplete:Object, p_extra:Object): Number {
81 p_extra.oldText = p_obj.text;
82 p_extra.newText = p_originalValueComplete;
83 return p_extra.newText.length;
84 }
85
86
87
88
89
90
91
92
98 public static function _generic_color_splitter (p_value:Number, p_parameters:Array):Array {
99 var nArray:Array = new Array();
100 nArray.push({name:p_parameters[0], value:AuxFunctions.numberToR(p_value)});
101 nArray.push({name:p_parameters[1], value:AuxFunctions.numberToG(p_value)});
102 nArray.push({name:p_parameters[2], value:AuxFunctions.numberToB(p_value)});
103 return nArray;
104 }
105
106
107
108
109
110
113 public static function _textFormat_property_get (p_obj:Object, p_parameters:Array):Number {
114 var fmt:TextFormat = p_obj.getTextFormat();
115 var propertyName:String = p_parameters[0];
116 var isColor:Boolean = p_parameters[1];
117 if (!isColor) {
118
119 return (fmt[propertyName]);
120 } else {
121
122 var colorComponent:String = p_parameters[2];
123 if (colorComponent == "r") return AuxFunctions.numberToR(fmt[propertyName]);
124 if (colorComponent == "g") return AuxFunctions.numberToG(fmt[propertyName]);
125 if (colorComponent == "b") return AuxFunctions.numberToB(fmt[propertyName]);
126 }
127
128 return null;
129 }
130
131 public static function _textFormat_property_set (p_obj:Object, p_value:Number, p_parameters:Array):Void {
132 var fmt:TextFormat = p_obj.getTextFormat();
133 var propertyName:String = p_parameters[0];
134 var isColor:Boolean = p_parameters[1];
135 if (!isColor) {
136
137 fmt[propertyName] = p_value;
138 } else {
139
140 var colorComponent:String = p_parameters[2];
141 if (colorComponent == "r") fmt[propertyName] = (fmt[propertyName] & 0xffff) | (p_value << 16);
142 if (colorComponent == "g") fmt[propertyName] = (fmt[propertyName] & 0xff00ff) | (p_value << 8);
143 if (colorComponent == "b") fmt[propertyName] = (fmt[propertyName] & 0xffff00) | p_value;
144 }
145
146 p_obj.setTextFormat(fmt);
147 p_obj.setNewTextFormat(fmt);
148
149 }
150
151 }
152