Generating SWFs using Ming via CGI

Tim Wilson wilson at
Thu Jun 20 21:41:04 EDT 2002

Hi everyone,

I'm finishing up a class on building Flash animations. For my final 
project, I thought it would be cool to build a SWF (the Flash output file) 
using input from a Web form and processed using the Ming library 
( through CGI.

Ming is "an SWF output library and PHP module" that also provides a Python 
wrapper. There is a function reference at and examples at

I'm having trouble getting a simple example to work via cgi on my Web 
server. (I know it's not a cgi configuration problem. There are other CGI 
scripts that work fine.) I'm not sure how to set the Content-type header 
and then output the SWF movie.

Here's a short PHP script followed by my Python translation.

  $s = new 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 = new SWFMovie();
  $m->setDimension(320, 240);

  header('Content-type: application/x-shockwave-flash');

This script is found at

Here's my Python translation.


from ming import *

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)

print "Content-type: applicaton/x-shockwave.flash\n"

Note, I can substitute'shape.swf') for m.output() and the script 
works fine. But I want the swf to be viewed immediately in the browser.

BTW, running the Python version listed above produces the following in my 
Web server's error log:

[Thu Jun 20 20:08:15 2002] [error] [client] malformed header 
from script. Bad header=FWSQ: /home/wilson/public_html/cgi-bin/

Running the script from the server's command line produces:

wilson at beethoven:~/public_html/cgi-bin$ python
Content-type: applicaton/x-shockwave.flash

            0@‘ÿÿPÿ5,†G໇Š&Q h†@wilson at beethoven:~/public_html/cgi-bin$

Can anyone provide a hint about how I can make this work?


Tim Wilson      | Visit Sibley online:         | Check out:
Henry Sibley HS | |
W. St. Paul, MN |                              |
wilson at |   <dtml-var pithy_quote>     |

More information about the Python-list mailing list