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

Animation

Adding animation to your Flash movies is both fun and taxing. The key to animation is the SWFDisplayItem object returned by the add() function of your movie object. SWFDisplayItem objects have a variety of functions that allow you to move, rotate, scale, and skew your objects easily. This next example demonstrates some basic animation:

    $font = new SWFFont("Impact.fdb");
    $text = new SWFText();
    $text->setFont($font);
    $text->moveTo(300, 500);
    $text->setColor(0, 0xff, 0);
    $text->setHeight(200);
    $text->addString("Text is surprisingly easy");

    $movie = new SWFMovie();
    $movie->setDimension(6400, 4800);

    $displayitem = $movie->add($text);

    for($i = 0; $i < 100; ++$i) {
            $displayitem->rotate(-1);
            $displayitem->scale(1.01, 1.01);
            $movie->nextFrame();
    }

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

Although that code is largely the same as a previous script, the $movie->add($text) line has now changed so that the return value is captured and stored in $displayitem.

The script then runs through a loop 100 times, each time calling rotate(), scale(), and nextFrame(). Animation works by defining the initial state of the movie, advancing the frame, then specifying changes from the previous frame. In practice, this means you use nextFrame() each time you want to move forward to the next frame of your Flash animation.

The rotate() function takes a single parameter, which is the floating-point value of the amount to rotate your SWFDisplayItem object from its current rotation. ...

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