blob: 9199229393a930d50bee0c533b0d8517cc74add1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
class Css {
private var text_align:String;
private var font_size:String;
private var text_decoration:String;
private var margin:String;
public var margin_top:Number;
public var margin_bottom:Number;
public var margin_left:Number;
public var margin_right:Number;
private var padding:String;
public var padding_top:Number=0;
public var padding_bottom:Number=0;
public var padding_left:Number=0;
public var padding_right:Number=0;
private var font_weight:String;
private var font_style:String;
private var font_family:String;
private var color:String;
private var stop_process:Number; // Flag for disable checking
private var bg_colour:String;
private function trim( txt:String )
{
var l = 0; var r = txt.length - 1;
while(txt.charAt(l) == ' ' or txt.charAt(l) == "\t" ) l++;
while(txt.charAt(r) == ' ' or txt.charAt(r) == "\t" ) r--;
return txt.substring( l, r+1 );
}
private function removeDoubleSpaces( txt:String ) {
var aux:String;
var auxPrev:String;
aux = txt;
do {
auxPrev = aux;
aux.replace(' ',' ');
} while ( auxPrev.length != aux.length );
return aux;
}
private function ToNumber(cad:String) {
cad = cad.replace( 'px', '' );
if ( isNaN( Number(cad) ) ) {
return 0;
} else {
return Number(cad);
}
}
private function getAttribute( txt:String ) {
var arr:Array = txt.split(":");
if( arr.length==2 )
{
this.stop_process = 1;
this.set( arr[0], trim(arr[1]) );
}
}
public function get( cad:String ) {
switch (cad) {
case "text-align" : return this.text_align;
case "font-size" : return ToNumber(this.font_size);
case "text-decoration" : return this.text_decoration;
case "margin-top" : return this.margin_top;
case "margin-bottom" : return this.margin_bottom;
case "margin-left" : return this.margin_left;
case "margin-right" : return this.margin_right;
case "padding-top" : return this.padding_top;
case "padding-bottom" : return this.padding_bottom;
case "padding-left" : return this.padding_left;
case "padding-right" : return this.padding_right;
case "font-weight" : return ToNumber(this.font_weight);
case "font-style" : return this.font_style;
case "font-family" : return this.font_family;
case "color" : return this.color;
case "background-color" : return this.bg_colour;
default : return 0;
}
}
// FUCKING!! Flash without By reference String parameters on functions
public function set( cad:String, val:String )
{
cad = trim( cad );
switch( cad )
{
case "text-align" : this.text_align = val; break;
case "font-size" : this.font_size = val; break;
case "text-decoration" : this.text_decoration = val; break;
case "margin":
this.margin = setMargin(val);
break;
case "margin-top" : this.margin_top = ToNumber(val); break;
case "margin-bottom" : this.margin_bottom = ToNumber(val); break;
case "margin-left" : this.margin_left = ToNumber(val); break;
case "margin-right" : this.margin_right = ToNumber(val); break;
case 'padding':
this.padding = setPadding(val);
break;
case "padding-top" : this.padding_top = ToNumber(val); break;
case "padding-bottom" : this.padding_bottom = ToNumber(val); break;
case "padding-left" : this.padding_left = ToNumber(val); break;
case "padding-right" : this.padding_right = ToNumber(val); break;
case "font-weight" : this.font_weight = val; break;
case "font-style" : this.font_style = val; break;
case "font-family" : this.font_family = val; break;
case "color" : this.color = _root.get_colour( val ); break;
case "background-color":
this.bg_colour = _root.get_colour( val);
break;
}
}
private function setPadding( val:String )
{
val = trim( val );
var arr:Array = val.split(' ');
switch( arr.length )
{
// margin: 30px;
case 1:
this.padding_top = ToNumber(arr[0]);
this.padding_right = ToNumber(arr[0]);
this.padding_bottom = ToNumber(arr[0]);
this.padding_left = ToNumber(arr[0]);
break;
// margin: 15px 5px;
case 2:
this.padding_top = ToNumber(arr[0]);
this.padding_right = ToNumber(arr[1]);
this.padding_bottom= ToNumber(arr[0]);
this.padding_left = ToNumber(arr[1]);
break;
// margin: 15px 5px 10px;
case 3:
this.padding_top = ToNumber(arr[0]);
this.padding_right = ToNumber(arr[1]);
this.padding_bottom= ToNumber(arr[2]);
this.padding_left = ToNumber(arr[1]);
break;
// margin: 1px 2px 3px 4px;
default:
this.padding_top = ToNumber(arr[0]);
this.padding_right = ToNumber(arr[1]);
this.padding_bottom= ToNumber(arr[2]);
this.padding_left = ToNumber(arr[3]);
}
}
private function setMargin( val:String )
{
val = trim( val );
var arr:Array = val.split(' ');
switch( arr.length )
{
// margin: 30px;
case 1:
this.margin_top = ToNumber(arr[0]);
this.margin_right = ToNumber(arr[0]);
this.margin_bottom= ToNumber(arr[0]);
this.margin_left = ToNumber(arr[0]);
break;
// margin: 15px 5px;
case 2:
this.margin_top = ToNumber(arr[0]);
this.margin_right = ToNumber(arr[1]);
this.margin_bottom= ToNumber(arr[0]);
this.margin_left = ToNumber(arr[1]);
break;
// margin: 15px 5px 10px;
case 3:
this.margin_top = ToNumber(arr[0]);
this.margin_right = ToNumber(arr[1]);
this.margin_bottom= ToNumber(arr[2]);
this.margin_left = ToNumber(arr[1]);
break;
// margin: 1px 2px 3px 4px;
default:
this.margin_top = ToNumber(arr[0]);
this.margin_right = ToNumber(arr[1]);
this.margin_bottom= ToNumber(arr[2]);
this.margin_left = ToNumber(arr[3]);
}
}
public function clear() {
this.text_align = undefined;
this.font_size = undefined;
this.text_decoration = undefined;
this.margin_top = undefined;
this.margin_bottom = undefined;
this.margin_left = undefined;
this.margin_right = undefined;
this.font_weight = undefined;
this.font_style = undefined;
this.font_family = undefined;
this.color = undefined;
}
public function Css( txt:String )
{
// To lower case
txt.toLowerCase();
// monk.e.boy: remove the { and }
txt = txt.replace( '{', '' );
txt = txt.replace( '}', '' );
// monk.e.boy: setup some default values.
// does this confilct with 'clear()'?
this.margin_top = 0;
this.margin_bottom = 0;
this.margin_left = 0;
this.margin_right = 0;
this.color = '#000000';
// Splitting by the ;
var arr:Array = txt.split(";");
// Checking all the types of css params we accept and writing to internal variables of the object class
for( var i = 0; i < arr.length; i++)
{
getAttribute(arr[i]);
}
}
}
|