SWF Recipes
As soon as you start using the Ming library to dynamically generate SWF files with Perl, you start to run into some issues that may make you think of turning to a tool like Flash. The simple act of drawing a circle, for example, is not as simple as you would think, as SWF only allows the use of cubic Bezier curves.
This section anticipates a few of these issues, and provides solutions to the following:
Drawing a circle with cubic Bezier curves
Creating a preloader with Ming
Using a custom XML file format that can be used to assemble composite documents from previously created movie clips
Using the XMLSocket ActionScript object to create a chat client that communicates with a Perl-based chat server
Drawing a Circle
The SWF specification allows you to represent curved lines using cubic Bezier curves. With only one control point, it is impossible to draw a perfect circle using only cubic Bezier curves. However, by applying a little math, we can get a pretty good approximation.
SWF generation tools such as Flash provide their own circle objects that construct a group of cubic Bezier curves to accurately represent a circle. Since we are creating an SWF file at a relatively low level (with the Ming library), we have to do some of the math ourselves. There’s an upside to the hands-on approach, however—our circle generation script is able to draw a circle using any number of arc segments. This is useful for morphing with circles, where the starting shape must have the same number of ...
Get Perl Graphics Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.