PHP How to Create a Flash Movie

Jan 17, 2009 Author: GDchart-Master

To create a new Flash movie you need to invoke an instance of the SWFMovie class. Take a
look at the following line of code to see how to invoke the SWFMovie class:
$myMovie = new SWFMovie();
The variable $myMovie now contains an instance of the SWFMovie class. Now that you have an
instance of SWFMovie you can specify the fundamentals of your movie, such as movie
dimensions, frame rate, and background color. After you have specified these fundamentals
of your movie you could output it to the browser.
To set the dimensions of your movie, the SWFMovie class contains a member function called
setDimension(). The setDimension() function takes two arguments: the width and the height
(in pixels) you want your movie to be. Take a look at the following line of code to see how
to set the dimension of your dynamic Flash movie:

$myMovie->setDimension(400, 300);


This sets the $myMovie Flash piece to a width of 400 pixels and a height of 300 pixels. Now
that you have set the dimensions of your Flash piece you need to specify its frame rate.

Your frame rate specifies the number of frames per second that will be displayed. A Flash

movie is just a series of frames, sort of like a cartoon. So to display an animation you
would flip through different frames.
To set the frame rate you use the setRate() function. This function takes one parameter:
an integer that specifies the number of frames per second that will be displayed.


$myMovie->setRate(30);


The above code snippet sets the movie to flip through its frames at 30 frames per second.
Now that you have specified the dimensions of your movie and the rate at which your
movie will play you need to set a background color.
To set the background color of your movie, the SWFMovie class contains a member function
called setBackground(). The setBackground() function takes three arguments, all integers.
The first argument is the red component of the color you wish to use. The second argument
is the green component, and the third and final argument is the blue component of
the color you wish to use. Take a look at the following code snippet. It sets the background
color of your Flash piece to black.

$myMovie->setBackground(0, 0, 0);


Now that you have created a basic Flash piece, and I mean basic, you will want some way
to display it to the screen. It’s a good thing that the SWFMovie class contains a member function
called output() that writes the output to the browser. To use it, you need to specify the
content type just like you did when you were creating your own dynamic graphics. Take a
look at the following lines of code:

header(“Content-type:application/x-shockwave-flash”);
$myMovie->output();
Let’s put all this together and take a look at it to see the results of all this code.


<?php
$myMovie = new SWFMovie();
$myMovie->setDimension(400, 300);
$myMovie->setRate(30);
$myMovie->setBackground(0, 0, 0);
// Now output the movie
header(“Content-type:application/x-shockwave-flash”);
$myMovie->output();
?>


Hmmm . . . notice how the whole Flash piece fills the browser no matter how large it is
even though you specified the dimensions of the Flash movie? It does this because a Flash
piece can scale itself dynamically because it uses vector graphics. So in order to keep the

Flash piece in the dimensions you specified, you need to embed it into an <object> tag and
save the Flash movie to disk. Take a look at the following example to see how to do that:

<html>
<body>
<OBJECT classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000”
codebase=”http://download.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=6,0,0,0”
WIDTH=”400” HEIGHT=”300” id=”flashTest”>
<PARAM NAME=movie VALUE=”example01.php”>
<EMBED src=”example01.php” WIDTH=”400” HEIGHT=”300”
TYPE=”application/x-shockwave-flash”
PLUGINSPAGE=”http://www.macromedia.com/go/getflashplayer”></EMBED>
</OBJECT>
</body>
</html>


views 5075
  1. Add New Comment