4 <title>SWFC Manual</title>
7 swfc is a tool for generating flash files. You can write small simple scripts
8 and then have them compiled to SWF Flash Animations.
14 This comment aims to give a short overview over the tags defined in guide.xslt.
17 Markups and Highlights:
23 <f>filename or pathname</f>
24 <c>variable name, command</c> ("c" stands for "code")
38 <a>http://www.quiss.org</a> OR
39 <a href=http://www.quiss.org>Quiss</a>
41 Shell scripts, commands to execute:
43 <shell>tail /var/log/messages</shell>
47 <code lang="sc"> (The lang= is optional)
56 <tr><td>Apples</td><td>Pears</td></tr>
57 <tr><td>3</td><td>4</td></tr>
70 Something to be careful about
75 <chapter title="Basic usage of swfc">
77 <section><title>Calling swfc</title>
81 swfc is command line based. You call it via
83 <shell>$ swfc file.sc</shell>
85 The filename of what is generated depends on the filename of the script (<f>file.sc</f>),
86 the filename given inside the script, and the optional <c>-o</c> passed to swfc.
91 Though swfc is a command-line utility, there also exists a nice graphical
92 frontend for it, called Swifty.
97 <section><title>A simple swfc example</title>
100 Let's create simple SWF file, shall we?
101 The following script creates a red box with a yellow border. On the right side you
102 see the script used, on the left side the swf file that is generated.
106 .flash name="box.swf"
107 .box b1 100 100 color=yellow fill=red
108 .put b1 pin=center scale=0%
110 .change b1 pin=center scale=100%
112 .change b1 pin=center scale=0%
117 The <c>.box</c> command creates the box. Every object that is created must also be explicitly
118 put into the scene using <c>.put</c> to become visible.
121 Change, on the other hand, modifies an already existing object.
122 It works gradually: In the example above, the change happens over 100 frames.
123 If you want to change an object suddently from one frame to the next, you
124 would use the <c>.jump</c> command.
129 <section><title>Color transforms</title>
132 You can define a number of parameters in the <c>.put</c>, <c>.change</c> and <c>.jump</c>
133 tags. Among those are the color transform parameters <c>red</c>, <c>green</c>,
134 <c>blue</c> and <c>alpha</c>.
135 Furthermore, for convenience, there's also <c>luminance</c>, which sets <c>red</c>, <c>green</c> and
136 <c>blue</c> in one go.
139 Each one of these consists of two parts: The multiplicator and the shift.
141 <c> ±<multiplicator>±<shift> </c>.
142 So, for example, to make an object 50% brighter, you would use
143 <c>luminance=+128</c>. Notice that all color components inside the transformed object in the range 128-255
144 will be mapped to 255 with this. To map 0 to 128, 255 to 255, but 128 to 192, you would
145 use <c>luminance=0.5+128</c>.
148 You can also specify negative values for both <c><mutliplicator></c> and <c><shift></c>.
149 This makes it e.g. possible to invert an object: <c>luminance=-1+255</c>.
152 The following example demonstrates a few of the possible transforms:
157 .flash name="cxform.swf" version=5 fps=25
159 .jpeg s1 "photo.jpeg" quality=80%
161 .put s1 x=50 y=50 scalex=110 scaley=110
163 .change s1 x=0 y=0 scalex=210 scaley=210 red=-1+255 green=-1+255 blue=-1+255 #invert
165 .change s1 x=100 y=50 scalex=110 scaley=110 red=0 green=+0 blue=+0 #remove red
167 .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=2 blue=-1+255 #amplify green, invert blue
169 .change s1 x=50 y=100 scalex=110 scaley=110 red=2-128 green=-2+255 blue=+0.7+40 #alien glow
171 .change s1 x=0 y=0 scalex=210 scaley=210 red=8-1024 green=8-1024 blue=8-1024 #palette reduce
173 .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=+0 blue=+0 #back to normal
175 .change s1 x=105 y=105 scalex=0 scaley=0 luminance=0 #fadeout
179 A very useful fact is also that you can color transform the alpha component.
180 So to fade any object into the background, you would simply transform it's
181 alpha color: E.g. <c>alpha=64</c> would make the object 75% transparent.
182 This is used in an example further below.
188 <chapter title="Fonts">
192 swfc has font support. That means you can also insert texts into
194 The easiest way to load a font is to do something like
196 .font Arial filename="Arial.ttf"
199 You now have a font named <c>Arial</c> to play with.
200 For example, for the obligatory hello world program:
203 .flash name="helloworld.swf"
205 .font Arial filename="Arial.ttf"
206 .text helloworld font=Arial text="Hello World!"
212 The text argument expects UTF-8 strings. So if you want to
213 pass any special characters (umlauts, digraphs etc.), they have to
217 Besides TrueType fonts, swfc also supports native SWF fonts.
218 If you have a SWF with a font you would like to use, do a
222 Then write down the font ID of the font, and do a
224 swfextract -f <fontid> file.swf -o myfont.swf
228 This will give you a file named myfont.swf which you can
229 also use in the <c>filename</c> parameter of <c>.font</c>.
233 Furthermore, you can convert TTF and Type1
234 fonts into SWF using <c>font2swf</c>:
236 font2swf Arial.ttf -o Arial.swf
238 The nice advantage of this is that you can play
239 Arial.swf in the flash player and see what the
241 (Also, loading a font in SWF format is slighly
242 faster than from a TTF file, as with TTFs spline
243 conversion has to take place).
249 So much for the basics. Now let's go to the more advanced
250 functionality around fonts.
254 Apart from being able to define text in your swfc files,
255 you can also define text <c>outlines</c>.
256 Those are not real characters but rather abstract vector
257 objects which you can use in other commands.
261 .flash name="fontoutline.swf"
262 .font Arial "Arial.swf"
263 .textshape helloworld font=Arial size=200% text="Hello World"
264 .filled filled_helloworld outline=helloworld fill=blue line=3 color=green
265 .put filled_helloworld
269 Here, <c>.textshape helloworld</c> defines an outline named "helloworld",
270 which is then used to construct a filled outline named filled_helloworld.
272 To make this a little more interesting, let's fill with a gradient instead
276 .flash name="fontgradient.swf"
277 .font Arial "Arial.swf"
278 .textshape helloworld font=Arial text="SHADE"
286 .filled filled_helloworld outline=helloworld fill=whitefade line=1 color=#2c2c2c
287 .put filled_helloworld scale=200%
291 While at it, you can also fill with an image:
294 .flash name="fontimage.swf"
295 .font courier "Courier.swf"
296 .jpeg beach "beach.jpg"
297 .textshape text font=courier text="HOLIDAY"
299 .filled filled_text outline=text fill=beach line=1 color=#2c2c2c
300 .put filled_text scale=200%
304 But let's get back to normal <c>.text</c> characters.
305 The following demonstrates that you can treat objects defined
306 with <c>.text</c> like normal shapes, i.e., scale them, move them, and use
310 .flash name="text5.swf"
311 .font courier "Courier.swf"
312 .text hithere text="HELLO" font=courier size=200%
313 .jpeg scenery "scenery.jpg"
316 .startclip hithere pin=center x=100 y=75 scale=50% #text clips...
317 .put scenery scale=50%
320 .change hithere rotate+=360 pin=center scale=100%
326 The last two examples look similar, but their underlying structure
327 is different: The first is a shape object filled with
328 image data (that is, a texture), while the second uses a normal
329 text object to clip an rectangular image.
333 Also, <c>.text</c> takes a color attribute (that's actually
334 the poor man's version of the more advanced filling options
335 that <c>.textshape</c> in conjunction with <c>.filled</c> offers),
336 which is used here together with the alpha parameter of <c>.change</c>:
340 .flash name="text6.swf"
341 .font times "Times.swf"
342 .text hello text="HELLO" font=times size=100% color=blue
343 .text world text="WORLD" font=times size=100% color=red
346 .put hello pin=center x=50 y=50
347 .put world pin=center x=50 y=50 alpha=25%
349 .change hello rotate+=360 pin=center alpha=25%
350 .change world rotate-=360 pin=center alpha=100%
358 A special type of text in SWF is the <c>edittext</c>, which
359 can be modified by the viewer. It's content can also be queried
360 and set from ActionScript (see below).
361 You can generate this type of text with the <c>.edittext</c> command:
364 .flash name="edittext.swf" bbox=210x110
365 .font Arial "Arial.swf"
366 .edittext myedittext font=Arial size=20%
368 color=blue border multiline wordwrap
369 text="Edit me!\nClick with your mouse on this text to edit it."
370 .put myedittext x=3 y=3
378 <chapter title="ActionScript">
381 <c>swfc</c> has Actionscript support.
382 For normal actionscript, which is executed once a given frame
383 is reached, just open an <c>.action</c> block, and write
384 the ActionScript into the block:
387 .flash name="action.swf" bbox=300x300 fps=50
389 .box mybox color=blue fill=green width=100 height=100
395 mybox._x = 100*Math.cos(_root.angle)+100;
396 mybox._y = 100*Math.sin(_root.angle)+100;
407 Or, for much more interesting ActionScript examples, see
409 <a href="http://technoargia.free.fr/swftools/examples/flash_eyes/flash_eyes.html">Flash Eyes</a>
411 <a href="http://melusine.eu.org/syracuse/flash/20040429/fabrique/">source</a>
412 of Jean-Michel Sarlat's
413 <a href="http://melusine.eu.org/syracuse/flash/20040429/">Mandelbrot explorer</a>.
420 <chapter title="Buttons">
422 Actionscript comes in handy when dealing with SWF Buttons.
425 A button defines, in SWF context, an object sensitive to mouse movement,
426 mouse buttons, and key presses.
429 The following is a trivial example: Four objects which change their shape
430 once the cursor is over it.
432 .flash name="button1.swf" fps=50
434 .box box1 color=white fill=#336633 width=50 height=50
435 .box box2 color=white fill=#99cc99 width=100 height=100
437 .show box1 as=shape x=25 y=25
438 .show box2 as=hover x=12.5 y=12.5
443 .put b2=mybutton1 x=100 red=+255
444 .put b3=mybutton1 y=100 green=+255
445 .put b4=mybutton1 x=100 y=100 blue=+255
451 The <c>.show</c> command (which can only be used inside <c>.button</c>) has a syntax
452 very similar to <c>.put</c>.
453 For every shape a button uses, you can specify the position, color transform, scaling,
454 rotation etc. just like with <c>.put</c>.
457 The only <i>real</i> difference between those two commands is the <c>as</c> parameter:
458 with that you tell the button when to display that specific shape.
459 There are four allowed parameters to <c>as</c>:
461 <li><b>idle</b> The shape to display when the button is idle, that is, the
462 mouse is somewhere else, and not over the button.
463 </li><li><b>hover</b> The shape to display if the mouse cursor is <i>inside</i> the button.
464 What exactly is <i>"inside"</i> is defined by <b>area</b>:
465 </li><li><b>area</b> This shape is not displayed. It serves as bounding box (actually,
466 bounding polygon) for the button. A button considers itself
467 active (that is, the <c>hover</c> shape is active, not the <c>idle</c>
468 shape) if the mouse is inside this area. Also, mouse button clicks
469 have to be in this area for this button.
470 </li><li><b>pressed</b> The shape to display if the user clicks on the button. This shape
471 is displayed as long as the mouse button is down.
477 <section><title>Another button example: tooltips</title>
479 Due to the fact that button shapes can be put <i>anywhere</i> especially
480 outside the active area, it's easy to generate tooltips or subtitles.
483 .flash name="tooltips.swf" fps=50
488 .font arial Arial.ttf
489 .edittext tooltip_fence text="fence" readonly color=green font=arial width=200 height=50 size=20%
490 .edittext tooltip_wheel text="wheel" readonly color=green font=arial width=200 height=50 size=20%
491 .edittext tooltip_tree text="tree" readonly color=green font=arial width=200 height=50 size=20%
492 .edittext tooltip_mountain text="mountain" readonly color=green font=arial width=200 height=50 size=20%
494 .box box1 fill=red width=1 height=1
496 .show box1 as=area x=0 y=0
497 .show tooltip_fence as=hover x=25 y=25 scalex=100 scaley=100 alpha=50%
498 .show tooltip_fence as=idle x=25 y=25 scalex=100 scaley=100 alpha=50%