Chapter 18. Creating Flash

PHP uses the Ming library for generating Flash movies, which is licensed under the LGPL. The library is also object-oriented and actively developed by the maintainers. In Flash, all values specifying some form of distance, length, height, or size are in twips, which means a twentieth of a pixel. Flash movies scale to fit their container, though, so these measurements are entirely arbitrary figures.

A Simple Movie

One of the biggest advantages to Ming is that it is object-oriented, so you create a shape object, tell it what color it should be, then add it to the movie. The same process applies for all the other operations in Ming, which makes the code easy to read. Here is a script that creates a basic movie:

    $mov = new SWFMovie();
    $mov->setDimension(200,20);

    $shape = new SWFShape();
    $shape->setLeftFill($shape->addFill(0xff, 0, 0));
    $shape->movePenTo(0,0);
    $shape->drawLineTo(199,0);
    $shape->drawLineTo(199,19);
    $shape->drawLineTo(0,19);
    $shape->drawLineTo(0,0);

    $mov->add($shape);
    header('Content-type: application/x-shockwave-flash');
    $mov->output();

Save that script as ming1.php.

First we create a new instance of the SWFMovie class and assign it to our $movvariable. An SWFMovie object allows you to manipulate attributes of the movie as a whole —size, color, animation frame rate, etc. It is also used to add other Flash objects to your movie, so you must hold on to the SWFMovie object that was created.

The setDimension() function is an SWFMovie function that ...

Get PHP in a Nutshell 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.