#native_company# #native_desc#

Graphing With Flash (SWF)

By Bryan Mattern
on January 10, 2001

Introduction to SWF and Flash

SWF is the file format used by Macromedia Flash to deliver graphics, animation and
sound to users on the Internet. Flash enables you to provide a very rich and dynamic interface to the user.
Almost 90% of web users can view SWF content without having to install a browser based plug-in, and over
200 million people have downloaded the Flash player. Macromedia opened the specifications for SWF in
April 1998 and SWF support was added to PHP in PHP 4(rc2).
PHPs built-in ability to dynamically create images is one feature that impresses me. It makes reports
and interfaces look much more professional and visually pleasing. Initially, I used the various GD
code floating around the net to create the graphs I needed to better represent data for various projects
I had done. I got really sick of the aliasing and choppyness of the generated images, so decided to try
and see if it could be done with vector graphics instead. I think you will agree that the result looks
much better. If a picture is worth a thousand words, wonder what a Flash movie is worth?
In this example, I try to keep things simple and just present the basics. My goal was basically
just create a drop in for GD generated GIFs and PNGs. You can choose to add enhancements, such as any
of the visual effects Flash is famous for. For example, you could make the graph fade in, fly around
into place when the page is loaded or pull pieces of the pie out dynamically. Your imagination is the
only limitation to what can be done with the PHP SWF functions.
How you get the data you choose to graph is an exercise best left up to the reader. Since this
article is about dynamic creation of flash files, I will be using an imaginary table as a data set
to create a graphical representation for this example. You will need to intelligently look at your
data and decide what the best way to present this data will be. In most of the cases, I have
found a pie graph to fit the bill, so this is the example I will use. A line, bar or area graph could
easily be created in a similar manner.
Assume we are trying to see what proportion of cities we shipped our packages of jumbo nightcrawlers to.
We decide to store this data in a table called “city” in our database called “world”. Let’s get to work
setting up a database table and enter data for the example.