Generating SWFs using Ming via CGI

Tim Wilson wilson at visi.com
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 
(http://ming.sourceforge.net/) through CGI.

Ming is "an SWF output library and PHP module" that also provides a Python 
wrapper. There is a function reference at 
http://ming.sourceforge.net/docs/index.php?mode=py and examples at 
http://ming.sourceforge.net/examples/index.html

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);
  $m->setRate(12.0);
  $m->add($s);
  $m->nextFrame();

  header('Content-type: application/x-shockwave-flash');
  $m->output();
?>

This script is found at 
http://ming.sourceforge.net/examples/example.php?name=shape

Here's my Python translation.

#!/usr/bin/python

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)
m.setRate(12.0)
m.add(s)
m.nextFrame()

print "Content-type: applicaton/x-shockwave.flash\n"
m.output()

Note, I can substitute m.save('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 208.42.140.222] malformed header 
from script. Bad header=FWSQ: /home/wilson/public_html/cgi-bin/shape.py

Running the shape.py script from the server's command line produces:

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

FWSQp
     €–
       Cÿÿÿp
            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

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



More information about the Python-list mailing list