[Tutor] Generating SWFs on the fly using Ming and Python CGI

Tim Wilson wilson@visi.com
Wed, 19 Jun 2002 23:13:17 -0500


Hi everyone,

I've got an interesting problem here and I'm hoping someone will have
some hints.

I'm finishing up a course on building Flash animations and I discovered
Ming (http://ming.sourceforge.net/), "an SWF output library and PHP
module." There is also a Python wrapper that makes it possible to do all
this from python. I told the professor at the beginning of the course
that I'd like to find a way to generate SWF files without using
Macromedia's Flash software (love my Linux box).

I thought it would be interesting to try to build a Flash SWF on the fly
using input from a Web form. Here's the code I've got at this point.
The problem is at the very end.

#!/usr/bin/python

from ming import *
import sys

s = SWFShape()
s.setLine(4, 0x7f, 0, 0)
s.setRightFill(s.addFill(0xff, 0, 0))
s.movePenTo(10, 10)
s.drawLineTo(310, 10)
s.drawLineTo(310, 230)
s.drawCurveTo(10, 230, 10, 10)

m = SWFMovie()
m.setDimension(320, 240)
m.setRate(12.0)
m.add(s)
m.nextFrame()

print """Content-type: application/x-shockwave-flash\n\n"""
m.save(sys.stdout)

You can see what the SWF should look like at
http://qwerk.org/~wilson/cgi-bin/shape.swf

There's no HTML form input at this point, I'm just trying to get Python
to generate the SWF and return it to the Web browser. FWIW, there is
some documentation at http://ming.sourceforge.net/docs/index.php?mode=py
that lists the various methods. (I generated the working SWF by calling
the 'save()' method of my SWFMovie object.)

Anyone have any ideas here?

-Tim

-- 
Tim Wilson      |   Visit Sibley online:   | Check out:
Henry Sibley HS |  http://www.isd197.org   | http://www.zope.com
W. St. Paul, MN |                          | http://slashdot.org
wilson@visi.com |  <dtml-var pithy_quote>  | http://linux.com