forked from theflashbum/fcss
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReadMe.txt
More file actions
200 lines (151 loc) · 5.67 KB
/
ReadMe.txt
File metadata and controls
200 lines (151 loc) · 5.67 KB
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
Copyright (c) 2009 Jesse Freeman http://www.flashartofwar.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---- Introduction ----
F*CSS is a custom CSS parser for Flash. The main class called FStyleSheet (found
inside of the com.flashartofwar.fcss.stylesheets package), goes well beyond the
native StyleSheet class by supporting style inheritance, pseudo selectors, and
merging styles on the fly. The goal of F*CSS is to make styles something you can
apply to any of your classes instead of just TextFields. CSS is a great way to
define your class’s properties in an external file and F*CSS helps convert these
css styles into property/value pairs you can apply to any Object.
---- Examples ----
/** Sample CSS ***/
// Get some css. Normally you would load CSS from an external file but
// for this example we are going to put some CSS in a XML variable.
var css:XML = <css><![CDATA[
/* This is a class */
.TextField
{
border: true;
borderColor: red;
selectable: false;
}
/* This is an ID */
#demoStyle
{
color: red;
size: 30;
autoSize: left;
x: 50;
y: 50;
}
/* This is how you can inherit from another style */
#demoStyle #demoStyle2
{
y:100;
}
#demoStyle #demoTextFieldFactroy
{
y:160;
color: green;
borderColor: green;
}
/* This is how you do inline StyleSheets for TextFields */
#demoStyle #demoInlineStyleSheet
{
size:25;
y: 210;
styleSheet:.highLight,a,a:hover;
}
.highLight
{
color:#00ff00;
}
a
{
color:#0000ff;
text-decoration: underline;
}
a:hover
{
color:#000000;
text-decoration: none;
}
#demoShapeStyle
{
x:50;
y:10;
width:300;
height:25;
}
]]>
</css>;
/** Style A TextField **/
// Create a new StyleSheet
var styleSheet:IStyleSheet = new FStyleSheet( );
styleSheet.parseCSS(css.toString());
// Get a style (Returns an object with properties as strings)
var style:IStyle = styleSheet.getStyle("#demoStyle");
// Trace out the style's properties
trace("style", style);
// Create a TextField
var tf:TextField = new TextField();
// Use a TextFieldApplicator to apply the style to the TextField
var tfApplicator:TextFieldApplicator = new TextFieldApplicator();
tfApplicator.applyStyle(tf, style);
// Use TextField like you would normally
tf.htmlText = "F*CSS - Hello World";
addChild(tf);
/** Merging styles at runtime **/
// You can merge styles on the fly when you call getStyle().
// Here we merge .TextField with #demoStyle2 to setup a new TF.
// Lets get the 2 styles. Simply pass in any number
// of style names and separate them with a comma.
var style2:IStyle = styleSheet.getStyle(".TextField", "#demoStyle2");
// Trace out the style we just created
trace("style2 (Merged .TextField + #demoStyle2)", style2);
// Create a TextField
var tf2:TextField = new TextField();
// Use TextFieldUtility to apply the style to the TextField
tfApplicator.applyStyle(tf2, style2);
// Use TextField like you would normally
tf2.htmlText = "F*CSS Demo 2 - Hello World";
addChild(tf2);
/** How To Use The TextFieldFactory **/
// This assumes you are have created a StyleSheetCollection. If not, you will have to
// create a new FStyleSheet, parse css data then pass that into the factory.
// Create a new factory and pass in a reference to a IStyleSheet and an IApplicator
var tff:TextFieldFactory = new TextFieldFactory(tfApplicator, styleSheetCollection);
// The first param is the id and the second is the calls. It will
// automatically add # and . to the string to "emulate" how
// HTML/CSS would work.
var tf3:TextField = tff.createTextField("demoTextFieldFactroy", "TextField");
// Use TextField like you would normally
tf3.htmlText = "F*CSS TextFactory - Hello World";
addChild(tf3);
/** Add Native StyleSheets To TextField with F*CSS **/
// To use native StyleSheets you simply add the Style names into the
// F*CSS's StyleSheet param on any F*CSS Style. Check out
// .demoInlineStyleSheet to see what I am talking about
var tf4:TextField = tff.createTextField("demoInlineStyleSheet");
// Use TextField like you would normally
tf4.htmlText = "<a href='http://fcss.flashartofwar.com' target='_blank'>F*CSS</a> <span class='highLight'>Native</span> StyleSheet - Hello World";
addChild(tf4);
/** Style Any Object With StyleApplierUtil **/
// For this demo we are going to create a simple shape
// then use CSS to position it and change it's dimensions
var shape:Shape = new Shape();
shape.graphics.beginFill(0xff0000);
shape.graphics.drawRect(0,0,10,10);
shape.graphics.endFill();
addChild(shape);
// Get a Style
var shapeStyle:IStyle = styleSheetCollection.getStyle("#demoShapeStyle");
// Now you can apply the style to any object, lets use the
// shape as our target.
var styleApplicator:StyleApplicator = new StyleApplicator();
styleApplicator.applyStyle(shape,shapeStyle);