Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

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 allows ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page