LVIII. Shockwave Flash functions

PHP offers the ability to create Shockwave Flash files via Paul Haeberli's libswf module. You can download libswf at http://reality.sgi.com/grafica/flash/. Once you have libswf all you need to do is to configure --with-swf[=DIR] where DIR is a location containing the directories include and lib. The include directory has to contain the swf.h file and the lib directory has to contain the libswf.a file. If you unpack the libswf distribution the two files will be in one directory. Consequently you will have to copy the files to the proper location manually.

Once you've successfully installed PHP with Shockwave Flash support you can then go about creating Shockwave files from PHP. You would be surprised at what you can do, take the following code:

Example 1. SWF example


<?php
swf_openfile ("test.swf", 256, 256, 30, 1, 1, 1);
swf_ortho2 (-100, 100, -100, 100);
swf_defineline (1, -70, 0, 70, 0, .2);
swf_definerect (4, 60, -10, 70, 0, 0);
swf_definerect (5, -60, 0, -70, 10, 0);
swf_addcolor (0, 0, 0, 0);

swf_definefont (10, "Mod");
swf_fontsize (5);
swf_fontslant (10);
swf_definetext (11, "This be Flash wit PHP!", 1);

swf_pushmatrix ();
swf_translate (-50, 80, 0);
swf_placeobject (11, 60);
swf_popmatrix ();

for ($i = 0; $i < 30; $i++) {
    $p = $i/(30-1);
    swf_pushmatrix ();
    swf_scale (1-($p*.9), 1, 1);
    swf_rotate (60*$p,  'z');
    swf_translate (20+20*$p, $p/1.5, 0);
    swf_rotate (270*$p,  'z');
    swf_addcolor ($p, 0, $p/1.2, -$p);
    swf_placeobject (1, 50);
    swf_placeobject (4, 50);
    swf_placeobject (5, 50);
    swf_popmatrix ();
    swf_showframe ();
}

for ($i = 0; $i < 30; $i++) {
    swf_removeobject (50);
    if (($i%4) == 0) {
        swf_showframe ();
    }
}

swf_startdoaction ();
swf_actionstop ();
swf_enddoaction ();

swf_closefile ();
?>
     
It will produce the animation found at the following url.

Note: SWF support was added in PHP4 RC2.

Table of Contents
swf_openfile — Open a new Shockwave Flash file
swf_closefile — Close the current Shockwave Flash file
swf_labelframe — Label the current frame
swf_showframe — Display the current frame
swf_setframe — Switch to a specified frame
swf_getframe — Get the frame number of the current frame
swf_mulcolor — Sets the global multiply color to the rgba value specified
swf_addcolor — Set the global add color to the rgba value specified
swf_placeobject — Place an object onto the screen
swf_modifyobject — Modify an object
swf_removeobject — Remove an object
swf_nextid — Returns the next free object id
swf_startdoaction — Start a description of an action list for the current frame
swf_actiongotoframe — Play a frame and then stop
swf_actiongeturl — Get a URL from a Shockwave Flash movie
swf_actionnextframe — Go foward one frame
swf_actionprevframe — Go backwards one frame
swf_actionplay — Start playing the flash movie from the current frame
swf_actionstop — Stop playing the flash movie at the current frame
swf_actiontogglequality — Toggle between low and high quality
swf_actionwaitforframe — Skip actions if a frame has not been loaded
swf_actionsettarget — Set the context for actions
swf_actiongotolabel — Display a frame with the specified label
swf_enddoaction — End the current action
swf_defineline — Define a line
swf_definerect — Define a rectangle
swf_definepoly — Define a polygon
swf_startshape — Start a complex shape
swf_shapelinesolid — Set the current line style
swf_shapefilloff — Turns off filling
swf_shapefillsolid — Set the current fill style to the specified color
swf_shapefillbitmapclip — Set current fill mode to clipped bitmap
swf_shapefillbitmaptile — Set current fill mode to tiled bitmap
swf_shapemoveto — Move the current position
swf_shapelineto — Draw a line
swf_shapecurveto — Draw a quadratic bezier curve between two points
swf_shapecurveto3 — Draw a cubic bezier curve
swf_shapearc — Draw a circular arc
swf_endshape — Completes the definition of the current shape
swf_definefont — Defines a font
swf_setfont — Change the current font
swf_fontsize — Change the font size
swf_fontslant — Set the font slant
swf_fonttracking — Set the current font tracking
swf_getfontinfo — The height in pixels of a capital A and a lowercase x
swf_definetext — Define a text string
swf_textwidth — Get the width of a string
swf_definebitmap — Define a bitmap
swf_getbitmapinfo — Get information about a bitmap
swf_startsymbol — Define a symbol
swf_endsymbol — End the definition of a symbol
swf_startbutton — Start the definition of a button
swf_addbuttonrecord — Controls location, appearance and active area of the current button
swf_oncondition — Describe a transition used to trigger an action list
swf_endbutton — End the definition of the current button
swf_viewport — Select an area for future drawing
swf_ortho — Defines an orthographic mapping of user coordinates onto the current viewport
swf_ortho2 — Defines 2D orthographic mapping of user coordinates onto the current viewport
swf_perspective — Define a perspective projection transformation
swf_polarview — Define the viewer's position with polar coordinates
swf_lookat — Define a viewing transformation
swf_pushmatrix — Push the current transformation matrix back unto the stack
swf_popmatrix — Restore a previous transformation matrix
swf_scale — Scale the current transformation
swf_translate — Translate the current transformations
swf_rotate — Rotate the current transformation
swf_posround — Enables or Disables the rounding of the translation when objects are placed or moved