Ming: creating Flash movies 1

Ming is a library with a few utilities for the production of SWF files. It is written in C, but has several wrappers so it can be used with other languages: PHP, python, C++, Ruby and Perl. Ming currently has no GUI, so writing movies with complicated graphics is painstaking, at least until you have developed some generic functions for creating what you need. Still, even without spending time writing your own framework, Ming can create some effective and impressive movies. It also has a useful actionscript compiler for AS2.

The idea behind this series on Ming is that complete examples to compile and run are sometimes easier to begin with than a manual. However, Ming has a complete and useful manual, which is worth consulting.

Part 1 of the series gets us started by creating a very simple SWF. Compile and run the following C code to produce a movie (test.swf) that traces "test". Please note: if you run this in your browser, you will not see anything. You need to run it with a standalone player (e.g. Gnash), or find where the plugin sends its output.

#include <ming.h>

int main(int argc, char** argv)
{
    SWFMovie movie;
    SWFAction action;

    /* Call this before calling any other Ming functions! */
    Ming_init();

    movie = newSWFMovieWithVersion(7);

    /* Set the size and the frame rate of the movie */
    SWFMovie_setDimension(movie, 300, 200);
    SWFMovie_setRate (movie, 12.0);

    /* Add ActionScript to the frame */
    action = newSWFAction("trace('test');");
    SWFMovie_add(movie, (SWFBlock)action);

    /* This marks the end of a frame */
    SWFMovie_nextFrame(movie);

    /* Output the movie as test.swf */
    SWFMovie_save(movie, "test.swf");

    return 0;
}

Tip: make sure Ming is installed and use ming-config --libs to find the linker flags for gcc.