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

Flash Text

Following the rest of the library, text inside your Flash movie is manipulated using objects. The two key classes here are SWFFont and SWFText . The former holds the actual font shape data, whereas the latter holds information about the text as a whole, including color, position, string data, and the instance of SWFFont used to draw the letters.

The code to generate text works differently under Windows and Unix. First up, Linux users:

    $font = new SWFFont("Impact.fdb");
    $text = new SWFText();

    $text->setFont($font);
    $text->moveTo(200, 400);
    $text->setColor(0, 0xff, 0);
    $text->setHeight(200);
    $text->addString("Text is surprisingly easy");

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

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

The Windows code isn't far off, and the end result is the same:

    $font = new SWFFont("Impact");
    $text = new SWFTextField(); // new!
    $sprite = new SWFSprite(); // new!

    $text->setFont($font);
    $text->setColor(0, 0xff, 0);
    $text->setHeight(200);
    $text->addString("Windows is a little harder!");

    $spritepos = $sprite->add($text); // new!
    $spritepos->moveTo(200, 400); // new!

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

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

You'll need to alter your HTML file to display the new script, and also change the width and height attributes of the <embed> object so that the Flash movie is larger; otherwise, ...

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