How to translate SVG documents
for viewing them with any Flash player

Presented with 3 examples of SVG source code, compiled to SWF machine code

Gildas Trébaol
Software engineer
France

G. Trébaol works in the R&D of automated mechanic and hydraulic industrial systems.
He has a M.S. degree in mechanical engineering

Abstract

This document shows how the field of applications of SVG can be expanded
by reusing the SWF Flash players already installed on most computers and mobile devices.

This Web page is available in http://gtrebaol.free.fr/doc/svgopen/2008/presentation/.
This is an enhanced version of a similar paper presented at the SVG OPen 2008 conference, in zzzz.

Table of Contents

SVG versus Flash
Competing or complementary ?
Now, Flash works anywhere…
Advantage of using the SVG to SWF translation
SVG is easier for generating 2D graphics
Flash also provides XML-oriented or script-based generation tools, but not so easy
SVG is a convenient source code for producing SWF machine code
Demonstrations of SVG to SWF translations
Demo #1: programmed shapes, programmed animations
Demo #2: generated SVG shapes, programmed animations
Demo #3: generated SVG shapes, generated SVG animations
Flash & ActionScript reference documentation
Is Flash a proprietary standard or an open standard ?
How to choose between the ActionScript Version 1, Version 2 or Version 3 ?
How to get the PDF documentation for ActionScript V1 ?
Where to find the HTML documentation for developing with ActionScript V1, V2 or V3 ?

SVG versus Flash

Competing or complementary ?

Figure 1. The connection of SVG to SWF

flash | svg | gif

For 10 years, Vector Graphics have been an issue for Web designers and publishers:

Now, Flash works anywhere…

The Flash SWF format has won against SVG, especially after Adobe acquired Macromedia:

Table 1. Statistics of the plugins installed on Web browsers
Figure 2. 2003: Flash 98% SVG 17% Figure 3. 2004: Flash 98.2% SVG 11.9%
Figure 4. 2006: Flash 96% SVG 11.3% Figure 5. 2008: Flash 99% SVG 7.9%
Source : NPD - Media Metrix www.adobe.com/products/player_census/flashplayer/

Advantage of using the SVG to SWF translation

SVG is easier for generating 2D graphics

Despite a lack of interest for Web designers, SVG is still very convenient for technical applications:

Flash also provides XML-oriented or script-based generation tools, but not so easy

For generating Flash files from XML, Macromedia proposes the FLEX tool:

For generating Flash files from script files, the simplest way is to use the Ming package for PHP:

SVG is a convenient source code for producing SWF machine code

The SVG format can be considered as a high level language for 2D graphics, whereas
the SWF format can be considered as a universal machine code for 2D graphics:

Demonstrations of SVG to SWF translations

The 3 following examples are mixing vector graphics that are:

Demo #1: programmed shapes, programmed animations

This first example uses an advanced Flash programming technique. It shows:

Figure 6. A Flash MX 2004 application ported to SVG
and rebuilt with the SVG to SWF compiler

flash | svg | gif

Explanations about this example :

Demo #2: generated SVG shapes, programmed animations

This second example uses a medium level Flash programming technique. It shows:

Figure 7. A SVG file translated to SWF,
with a programmed sequence, textures, gradients, transformations

flash | svg | gif

Explanations about this example:

Demo #3: generated SVG shapes, generated SVG animations

This third example shows how to use SVG for generating a sequence of computed images,
and displaying it with a movie viewer embedded in a Windows application.

This technique is useful in CAD or engineering tools, for displaying animated simulation results:
the recorded sequence is smaller and more accurate with vector graphics than with a video format like AVI, MPG or FLV.

For using vector graphics embedded in an engineering application:

Figure 8. The four_bar.exe simulator:
SVG animation in a Flash window
flash | svg | gif

Explanations about this example :

Table 2. Comparison of SVG and Flash/SWF performances
Document format File size CPU load
SVG 40KB 50% note: with the Adobe SVG viewer, the CPU load is lower
SWF 15KB 1%

Flash & ActionScript reference documentation

Although Flash and ActionScript are not official Web standards, both Flash and ActionScript have a widely accessible reference documentation.

Is Flash a proprietary standard or an open standard ?

Flash is surely less open than SVG, and since Flash is a commercial property of Adobe, you may be afraid of depending on an opaque standard. Fortunately, the technical strategy of Macromedia and Adobe is open, and the successive versions of the Flash (SWF) file format specification are published:

These specifications are used by independent teams, for developing many Flash-compatible tools:

Figure 9. A SWF movie containing ActionScript,
generated with the SVG compiler and viewed with GameSWF

These independent initiatives are probably not a threat for the Adobe Flash commercial products,
but they show that Flash SWF can be considered as a reliable de facto standard.

How to choose between the ActionScript Version 1, Version 2 or Version 3 ?

The current Flash players for Windows or Linux are compatible with the different versions of the ActionScript language,
corresponding to different programming styles:

How to get the PDF documentation for ActionScript V1 ?

Table 3. Specifications of ActionScript V1
Language URL Mirror
English en/flash/mx2004/fl_actionscript_reference.pdf ActionScript_en.pdf
French fr/flash/mx2004/fl_actionscript_reference.pdf
German de/flash/mx2004/fl_actionscript_reference.pdf
Italian it/flash/mx2004/fl_actionscript_reference.pdf
Spanish es/flash/mx2004/fl_actionscript_reference.pdf

Where to find the HTML documentation for developing with ActionScript V1, V2 or V3 ?

If you prefer HTML, rather than PDF, the Adobe Web site provides online documentation for developing with the ActionScript object model:

Conclusion and future work

I hope that the SVG to SWF compiler presented in this paper will help
SVG to develop like the other Web standards promoted by the W3C.

A possible evolution would be the integration of XML 2D and XML 3D graphics :

Currently, the SVG to SWF compiler is a beta version software, developed as a hobby project.
The code is written in ANSI C language. It is mostly system-independent for the portability on Windows, POSIX, Linux and MacOS platforms.
If you are interested in commercial applications or in the development of this tool, your suggestions and comments are welcome !