Shockwave Flash functionsSWF
PHP offers the ability to create Shockwave Flash files via Paul
Haeberli's libswf module. You can download libswf at &url.swf;. Once you have libswf all you
need to do is to configure 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:
SWF example
]]>
SWF support was added in PHP 4 RC2.
The libswf does not have support for Windows. The development of
that library has been stopped, and the source is not available
to port it to another systems.
swf_openfileOpen a new Shockwave Flash fileDescriptionvoid
swf_openfilestring
filenamefloat
widthfloat
heightfloat
frameratefloat
rfloat
gfloat
b
The swf_openfile function opens a new file
named filename with a width of
width and a height of
height a frame rate of
framerate and background with a red color
of r a green color of
g and a blue color of
b.
The swf_openfile must be the first function
you call, otherwise your script will cause a segfault. If you
want to send your output to the screen make the filename:
"php://stdout" (support for this is in 4.0.1 and up).
swf_closefileClose the current Shockwave Flash fileDescriptionvoid
swf_closefileint
return_file
Close a file that was opened by the
swf_openfile function. If the
return_file parameter is set then the contents
of the SWF file are returned from the function.
Creating a simple flash file based on user input and outputting it
and saving it in a database
]]>
swf_labelframeLabel the current frameDescriptionvoid
swf_labelframestring
name
Label the current frame with the name given by the
name parameter.
swf_showframeDisplay the current frameDescriptionvoid
swf_showframe
The swf_showframe function will output the current frame.
swf_setframeSwitch to a specified frameDescriptionvoid
swf_setframeint
framenumber
The swf_setframe changes the active frame to
the frame specified by framenumber.
swf_getframeGet the frame number of the current frameDescriptionint
swf_getframe
The swf_getframe function gets the number of
the current frame.
swf_mulcolor
Sets the global multiply color to the rgba value specified
Descriptionvoid
swf_mulcolorfloat
rfloat
gfloat
bfloat
a
The swf_mulcolor function sets the global
multiply color to the rgba color
specified. This color is then used (implicitly) by the
swf_placeobject,
swf_modifyobject and the
swf_addbuttonrecord functions. The color of
the object will be multiplied by the rgba
values when the object is written to the screen.
The rgba values can be either positive or
negative.
swf_addcolor
Set the global add color to the rgba value specified
Descriptionvoid
swf_addcolorfloat
rfloat
gfloat
bfloat
a
The swf_addcolor function sets the global
add color to the rgba color specified.
This color is then used (implicitly) by the
swf_placeobject,
swf_modifyobject and the
swf_addbuttonrecord functions. The color of
the object will be add by the rgba values
when the object is written to the screen.
The rgba values can be either positive or
negative.
swf_placeobjectPlace an object onto the screenDescriptionvoid
swf_placeobjectint
objidint
depth
Places the object specified by objid in
the current frame at a depth of depth.
The objid parameter and the
depth must be between 1 and 65535.
This uses the current mulcolor (specified by
swf_mulcolor) and the current addcolor
(specified by swf_addcolor) to color the
object and it uses the current matrix to position the object.
Full RGBA colors are supported.
swf_modifyobjectModify an objectDescriptionvoid
swf_modifyobjectint
depthint
how
Updates the position and/or color of the object at the specified
depth, depth. The parameter
how determines what is updated.
how can either be the constant MOD_MATRIX
or MOD_COLOR or it can be a combination of both
(MOD_MATRIX|MOD_COLOR).
MOD_COLOR uses the current mulcolor (specified by the function
swf_mulcolor) and addcolor (specified by the
function swf_addcolor) to color the object.
MOD_MATRIX uses the current matrix to position the object.
swf_removeobjectRemove an objectDescriptionvoid
swf_removeobjectint
depth
Removes the object at the depth specified by
depth.
swf_nextidReturns the next free object idDescriptionint
swf_nextid
The swf_nextid function returns the next
available object id.
swf_startdoaction
Start a description of an action list for the current frame
Descriptionvoid
swf_startdoaction
The swf_startdoaction function starts the
description of an action list for the current frame. This must
be called before actions are defined for the current frame.
swf_actiongotoframePlay a frame and then stopDescriptionvoid
swf_actiongotoframeint
framenumber
The swf_actionGotoFrame function will go to
the frame specified by framenumber, play
it, and then stop.
swf_actiongeturlGet a URL from a Shockwave Flash movieDescriptionvoid
swf_actiongeturlstring
urlstring
target
The swf_actionGetUrl function gets the URL
specified by the parameter url with the
target target.
swf_actionnextframeGo foward one frameDescriptionvoid
swf_actionnextframe
Go foward one frame.
swf_actionprevframeGo backwards one frameDescriptionvoid
swf_actionprevframeswf_actionplay
Start playing the flash movie from the current frame
Descriptionvoid
swf_actionplay
Start playing the flash movie from the current frame.
swf_actionstop
Stop playing the flash movie at the current frame
Descriptionvoid
swf_actionstop
Stop playing the flash movie at the current frame.
swf_actiontogglequality
Toggle between low and high quality
Descriptionvoid
swf_actiontogglequality
Toggle the flash movie between high and low quality.
swf_actionwaitforframe
Skip actions if a frame has not been loaded
Descriptionvoid
swf_actionwaitforframeint
framenumberint
skipcount
The swf_actionWaitForFrame function will
check to see if the frame, specified by the
framenumber parameter has been loaded, if
not it will skip the number of actions specified by the
skipcount parameter. This can be useful
for "Loading..." type animations.
swf_actionsettargetSet the context for actionsDescriptionvoid
swf_actionsettargetstring
target
The swf_actionSetTarget function sets the
context for all actions. You can use this to control other flash
movies that are currently playing.
swf_actiongotolabel
Display a frame with the specified label
Descriptionvoid
swf_actiongotolabelstring
label
The swf_actionGotoLabel function displays
the frame with the label given by the
label parameter and then stops.
swf_enddoactionEnd the current actionDescriptionvoid
swf_enddoaction
Ends the current action started by the
swf_startdoaction function.
swf_definelineDefine a lineDescriptionvoid
swf_definelineint
objidfloat
x1float
y1float
x2float
y2float
width
The swf_defineline defines a line starting
from the x coordinate given by x1 and the
y coordinate given by y1 parameter. Up
to the x coordinate given by the x2
parameter and the y coordinate given by the
y2 parameter. It will have a width
defined by the width parameter.
swf_definerectDefine a rectangleDescriptionvoid
swf_definerectint
objidfloat
x1float
y1float
x2float
y2float
width
The swf_definerect defines a rectangle with
an upper left hand coordinate given by the x,
x1, and the y, y1.
And a lower right hand coordinate given by the x coordinate,
x2, and the y coordinate, y2
. Width of the rectangles border is given by the
width parameter, if the width is 0.0 then
the rectangle is filled.
swf_definepoly
Define a polygon
Descriptionvoid
swf_definepolyint
objidarray
coordsint
npointsfloat
width
The swf_definepoly function defines a
polygon given an array of x, y coordinates (the coordinates are
defined in the parameter coords). The
parameter npoints is the number of overall
points that are contained in the array given by
coords. The width
is the width of the polygon's border, if set to 0.0 the polygon
is filled.
swf_startshapeStart a complex shapeDescriptionvoid
swf_startshapeint
objid
The swf_startshape function starts a complex
shape, with an object id given by the
objid parameter.
swf_shapelinesolidSet the current line styleDescriptionvoid
swf_shapelinesolidfloat
rfloat
gfloat
bfloat
afloat
width
The swf_shapeLineSolid function sets the
current line style to the color of the
rgba parameters and width to the
width parameter. If 0.0 is given as a
width then no lines are drawn.
swf_shapefilloffTurns off fillingDescriptionvoid
swf_shapefilloff
The swf_shapeFillOff function turns off
filling for the current shape.
swf_shapefillsolid
Set the current fill style to the specified color
Descriptionvoid
swf_shapefillsolidfloat
rfloat
gfloat
bfloat
a
The swf_shapeFillSolid function sets the
current fill style to solid, and then sets the fill color to the
values of the rgba parameters.
swf_shapefillbitmapclip
Set current fill mode to clipped bitmap
Descriptionvoid
swf_shapefillbitmapclipint
bitmapid
Sets the fill to bitmap clipped, empty spaces will be filled by
the bitmap given by the bitmapid
parameter.
swf_shapefillbitmaptile
Set current fill mode to tiled bitmap
Descriptionvoid
swf_shapefillbitmaptileint
bitmapid
Sets the fill to bitmap tile, empty spaces will be filled by the
bitmap given by the bitmapid parameter
(tiled).
swf_shapemovetoMove the current positionDescriptionvoid
swf_shapemovetofloat
xfloat
y
The swf_shapeMoveTo function moves the
current position to the x coordinate given by the
x parameter and the y position given by
the y parameter.
swf_shapelinetoDraw a lineDescriptionvoid
swf_shapelinetofloat
xfloat
y
The swf_shapeLineTo draws a line to the x,y
coordinates given by the x parameter & the
y parameter. The current position is then
set to the x,y parameters.
swf_shapecurveto
Draw a quadratic bezier curve between two points
Descriptionvoid
swf_shapecurvetofloat
x1float
y1float
x2float
y2
The swf_shapecurveto function draws a
quadratic bezier curve from the x coordinate given by
x1 and the y coordinate given by
y1 to the x coordinate given by
x2 and the y coordinate given by
y2. The current position is then set to
the x,y coordinates given by the x2 and
y2 parameters
swf_shapecurveto3Draw a cubic bezier curveDescriptionvoid
swf_shapecurveto3float
x1float
y1float
x2float
y2float
x3float
y3
Draw a cubic bezier curve using the x,y coordinate pairs
x1, y1 and
x2,y2 as off curve
control points and the x,y coordinate
x3, y3 as an
endpoint. The current position is then set to the x,y coordinate
pair given by
x3,y3.
swf_shapearcDraw a circular arcDescriptionvoid
swf_shapearcfloat
xfloat
yfloat
rfloat
ang1float
ang2
The swf_shapeArc function draws a circular
arc from angle A given by the ang1
parameter to angle B given by the ang2
parameter. The center of the circle has an x coordinate given by
the x parameter and a y coordinate given
by the y, the radius of the circle is
given by the r parameter.
swf_endshape
Completes the definition of the current shape
Descriptionvoid
swf_endshape
The swf_endshape completes the definition of
the current shape.
swf_definefont
Defines a font
Descriptionvoid
swf_definefontint
fontidstring
fontname
The swf_definefont function defines a font
given by the fontname parameter and gives
it the id specified by the fontid
parameter. It then sets the font given by
fontname to the current font.
swf_setfontChange the current fontDescriptionvoid
swf_setfontint
fontid
The swf_setfont sets the current font to the
value given by the fontid parameter.
swf_fontsizeChange the font sizeDescriptionvoid
swf_fontsizefloat
size
The swf_fontsize function changes the font
size to the value given by the size
parameter.
swf_fontslantSet the font slantDescriptionvoid
swf_fontslantfloat
slant
Set the current font slant to the angle indicated by the
slant parameter. Positive values create a
foward slant, negative values create a negative slant.
swf_fonttrackingSet the current font trackingDescriptionvoid
swf_fonttrackingfloat
tracking
Set the font tracking to the value specified by the
tracking parameter. This function is used
to increase the spacing between letters and text, positive values
increase the space and negative values decrease the space between
letters.
swf_getfontinfo
The height in pixels of a capital A and a lowercase x
Descriptionarray
swf_getfontinfo
The swf_getfontinfo function returns an
associative array with the following parameters:
Aheight - The height in pixels of a capital A.
xheight - The height in pixels of a lowercase x.
swf_definetextDefine a text stringDescriptionvoid
swf_definetextint
objidstring
strint
docenter
Define a text string (the str parameter)
using the current font and font size. The
docenter is where the word is centered, if
docenter is 1, then the word is centered
in x.
swf_textwidthGet the width of a stringDescriptionfloat
swf_textwidthstring
str
The swf_textwidth function gives the width
of the string, str, in pixels, using the
current font and font size.
swf_definebitmapDefine a bitmapDescriptionvoid
swf_definebitmapint
objidstring
image_name
The swf_definebitmap function defines a
bitmap given a GIF, JPEG, RGB or FI image. The image will be
converted into a Flash JPEG or Flash color map format.
swf_getbitmapinfoGet information about a bitmapDescriptionarray
swf_getbitmapinfoint
bitmapid
The swf_getbitmapinfo function returns an
array of information about a bitmap given by the
bitmapid parameter. The returned array
has the following elements:
"size" - The size in bytes of the bitmap.
"width" - The width in pixels of the bitmap.
"height" - The height in pixels of the bitmap.
swf_startsymbolDefine a symbolDescriptionvoid
swf_startsymbolint
objid
Define an object id as a symbol. Symbols are tiny flash movies
that can be played simultaneously. The
objid parameter is the object id you want
to define as a symbol.
swf_endsymbolEnd the definition of a symbolDescriptionvoid
swf_endsymbol
The swf_endsymbol function ends the
definition of a symbol that was started by the
swf_startsymbol function.
swf_startbuttonStart the definition of a buttonDescriptionvoid
swf_startbuttonint
objidint
type
The swf_startbutton function starts off the
definition of a button. The type
parameter can either be TYPE_MENUBUTTON or TYPE_PUSHBUTTON. The
TYPE_MENUBUTTON constant allows the focus to travel from the
button when the mouse is down, TYPE_PUSHBUTTON does not allow the
focus to travel when the mouse is down.
swf_addbuttonrecord
Controls location, appearance and active area of the current button
Descriptionvoid
swf_addbuttonrecordint
statesint
shapeidint
depth
The swf_addbuttonrecord function allows you
to define the specifics of using a button. The first parameter,
states, defines what states the button can
have, these can be any or all of the following constants:
BSHitTest, BSDown, BSOver or BSUp. The second parameter, the
shapeid is the look of the button, this is
usually the object id of the shape of the button. The
depth parameter is the placement of the
button in the current frame.
swf_addbuttonrecord function example
swf_oncondition
Describe a transition used to trigger an action list
Descriptionvoid
swf_onconditionint
transition
The swf_onCondition function describes a
transition that will trigger an action list. There are several
types of possible transitions, the following are for buttons
defined as TYPE_MENUBUTTON:
IdletoOverUp
OverUptoIdle
OverUptoOverDown
OverDowntoOverUp
IdletoOverDown
OutDowntoIdle
MenuEnter (IdletoOverUp|IdletoOverDown)
MenuExit (OverUptoIdle|OverDowntoIdle)
For TYPE_PUSHBUTTON there are the following options:
IdletoOverUp
OverUptoIdle
OverUptoOverDown
OverDowntoOverUp
OverDowntoOutDown
OutDowntoOverDown
OutDowntoIdle
ButtonEnter (IdletoOverUp|OutDowntoOverDown)
ButtonExit (OverUptoIdle|OverDowntoOutDown)
swf_endbutton
End the definition of the current button
Descriptionvoid
swf_endbutton
The swf_endButton function ends the
definition of the current button.
swf_viewportSelect an area for future drawingDescriptionvoid
swf_viewportfloat
xminfloat
xmaxfloat
yminfloat
ymax
The swf_viewport function selects an area
for future drawing for xmin to
xmax and ymin to
ymax, if this function is not called the
area defaults to the size of the screen.
swf_ortho
Defines an orthographic mapping of user coordinates onto the
current viewport
Descriptionvoid
swf_orthofloat
xminfloat
xmaxfloat
yminfloat
ymaxfloat
zminfloat
zmax
The swf_ortho funcion defines a orthographic
mapping of user coordinates onto the current viewport.
swf_ortho2
Defines 2D orthographic mapping of user coordinates onto the
current viewport
Descriptionvoid
swf_ortho2float
xminfloat
xmaxfloat
yminfloat
ymax
The swf_ortho2 function defines a two
dimensional orthographic mapping of user coordinates onto the
current viewport, this defaults to one to one mapping of the area
of the Flash movie. If a perspective transformation is desired,
the swf_perspective function can be used.
swf_perspective
Define a perspective projection transformation
Descriptionvoid
swf_perspectivefloat
fovyfloat
aspectfloat
nearfloat
far
The swf_perspective function defines a
perspective projection transformation. The
fovy parameter is field-of-view angle in
the y direction. The aspect parameter
should be set to the aspect ratio of the viewport that is being
drawn onto. The near parameter is the
near clipping plane and the far parameter
is the far clipping plane.
Various distortion artifacts may appear when performing a
perspective projection, this is because Flash players only have
a two dimensional matrix. Some are not to pretty.
swf_polarview
Define the viewer's position with polar coordinates
Descriptionvoid
swf_polarviewfloat
distfloat
azimuthfloat
incidencefloat
twist
The swf_polarview function defines the
viewer's position in polar coordinates. The
dist parameter gives the distance between
the viewpoint to the world space origin. The
azimuth parameter defines the azimuthal
angle in the x,y coordinate plane, measured in distance from the
y axis. The incidence parameter defines
the angle of incidence in the y,z plane, measured in distance
from the z axis. The incidence angle is defined as the angle of
the viewport relative to the z axis. Finally the
twist specifies the amount that the
viewpoint is to be rotated about the line of sight using the
right hand rule.
swf_lookatDefine a viewing transformationDescriptionvoid
swf_lookatfloat
view_xfloat
view_yfloat
view_zfloat
reference_xfloat
reference_yfloat
reference_zfloat
twist
The swf_lookat function defines a viewing
transformation by giving the viewing position (the parameters
view_x, view_y, and
view_z) and the coordinates of a reference
point in the scene, the reference point is defined by the
reference_x, reference_y
, and reference_z parameters.
The twist controls the rotation along
with viewer's z axis.
swf_pushmatrix
Push the current transformation matrix back unto the stack
Descriptionvoid
swf_pushmatrix
The swf_pushmatrix function pushes the
current transformation matrix back onto the stack.
swf_popmatrix
Restore a previous transformation matrix
Descriptionvoid
swf_popmatrix
The swf_popmatrix function pushes the
current transformation matrix back onto the stack.
swf_scaleScale the current transformationDescriptionvoid
swf_scalefloat
xfloat
yfloat
z
The swf_scale scales the x coordinate of the
curve by the value of the x parameter, the
y coordinate of the curve by the value of the
y parameter, and the z coordinate of the
curve by the value of the z parameter.
swf_translateTranslate the current transformationsDescriptionvoid
swf_translatefloat
xfloat
yfloat
z
The swf_translate function translates the
current transformation by the x,
y, and z values
given.
swf_rotateRotate the current transformationDescriptionvoid
swf_rotatefloat
anglestring
axis
The swf_rotate rotates the current
transformation by the angle given by the
angle parameter around the axis given by
the axis parameter. Valid values for the
axis are 'x' (the x axis), 'y' (the y axis) or 'z' (the z axis).
swf_posround
Enables or Disables the rounding of the translation when objects
are placed or moved
Descriptionvoid
swf_posroundint
round
The swf_posround function enables or
disables the rounding of the translation when objects are placed
or moved, there are times when text becomes more readable because
rounding has been enabled. The round is
whether to enable rounding or not, if set to the value of 1, then
rounding is enabled, if set to 0 then rounding is disabled.