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