Index: phpdoc/en/functions/ming.xml
+++ phpdoc/en/functions/ming.xml
Ming functions for FlashMing (flash)
This documentation ist not finished yet. Don't start to translate it
or use it as a programming reference (dams <email protected>).
These functions are not yet available if PHP.
Introduction
Ming is an open-source (LGPL) library which allows you to create SWF
("Flash") format movies. Ming supports almost all of Flash 4's features,
including: shapes, gradients, bitmaps (pngs and jpegs), morphs ("shape
tweens"), text, buttons, actions, sprites ("movie clips"), streaming mp3,
and color transforms--the only thing that's missing is sound events.
Ming is not an acronym.
Note that all values specifying length, distance, size, etc. are in "twips",
twenty units per pixel. That's pretty much arbitrary, though, since the player
scales the movie to whatever pixel size is specified in the embed/object tag,
or the entire frame if not embedded.
Ming offers a number of advantages over the existing PHP/libswf module.
You can use Ming anywhere you can compile the code, whereas libswf is
closed-source and only available for a few platforms, Windows not one of
them. Ming provides some insulation from the mundane details of the SWF
file format, wrapping the movie elements in PHP objects. Also, Ming is
still being maintained; if there's a feature that you want to see, just
let us know &email.ming;.
Installation
To use Ming with PHP, you first need to build and install the Ming
library. Source code and installation instructions are available at the
Ming home page : &url.ming;
along with examples, a small tutorial, and the latest news.
Download the ming archive. Unpack the archive. Go in the
Ming directory. make. make install.
This will build libming.so and install it into /usr/lib/,
and copy ming.h into /usr/include/. Edit the PREFIX= line
in the Makefile to change the installation directory.
built into php (unix)
mkdir <phpdir>/ext/ming
cp php_ext/* <phpdir>/ext/ming
cd <phpdir>
./buildconf
./configure --with-ming <other config options>
build and install php as usual,
restart web server if necessary
built into php (unix)
download php_ming.so.gz
uncompress it and copy it to your php modules directory.
(you can find your php module directory by running php-config --extension-dir).
Now either just add 'extension=php_ming.so' to your php.ini
file, or put 'dl('php_ming.so');' at the head of all of your
Ming scripts.
How to use Ming
Ming introduces 13 new object in PHP, all with matching methods and
attributes. To use them, you need to know about
objects.
swfmovie.
swfshape.
swfdisplayitem.
swfgradient.
swfbitmap.
swffill.
swfmorph.
swftext.
swffont.
swftextfield.
swfsprite.
swfbutton.
SWFMovieCreates a new movie object, representing an SWF version 4 movie.Descriptionnew swfmovievoidswfmovie creates a new movie object,
representing an SWF version 4 movie.
SWFMovie has the following methods :
swfmovie->output,swfmovie->save,
swfmovie->add, swfmovie->remove,
swfmovie->nextframe, swfmovie->setbackground,
swfmovie->setrate, swfmovie->setdimension,
swfmovie->setframes et swfmovie->streammp3.
See examples in :
swfdisplayitem->rotateto, swfshape->setline,
swfshape->addfill... Any example will use this object.
SWFMovie->outputDumps your lovingly prepared movie out.Descriptionstring swfmovie->outputvoidswfmovie->output dumps your lovingly prepared movie out.
In PHP, preceding this with the command
<?php
header('Content-type: application/x-shockwave-flash');
?>
convinces the browser to display this as a flash movie.
See also swfmovie->save
See examples in :
swfmovie->streammp3, swfdisplayitem->rotateto,
swfaction... Any example will use this method.
SWFMovie->saveSaves your movie in a file.Descriptionstring swfmovie->savestring filenameswfmovie->save saves your movie to the
file named filename.
See also outputSWFMovie->addAdds any type of data to a movie.Descriptionstring swfmovie->addressource instanceswfmovie->add adds instance to
the current movie. instance is any type of data :
Shapes, text, fonts, etc. must all be add'ed to the movie to make this work.
For displayable types (shape, text, button, sprite), this returns an
SWFDisplayItem, a handle to the object in a display list. Thus, you can
add the same shape to a movie multiple times and get separate handles
back for each separate instance.
See also all other objects (adding this later), and
swfmovie->remove
See examples in :
swfdisplayitem->rotateto and
swfshape->addfill.
SWFMovie->removeRemoves the object instance from the display list.Descriptionstring swfmovie->removeressource instanceswfmovie->remove removes the object instance
instance from the display list.
See also swfmovie->addSWFMovie->setbackgroundSets the background color.Descriptionstring swfmovie->setbackgroundint redint greenint blueswfmovie->setbackground sets the background color. Why is
there no rgba version? Think about it. (Actually, that's not such a dumb
question after all- you might want to let the html background show through.
There's a way to do that, but it only works on IE4. Search the MM site for
details.)
SWFMovie->setrateSets the animation's frame rate.Descriptionstring swfmovie->setrateint ratenom_de_la_fonction sets the frame rate to
rate, in frame per seconds.
Animation will slow down if the player can't render frames fast enough- unless
there's a streaming sound, in which case display frames are sacrificed to
keep sound from skipping.
SWFMovie->setdimensionSets the movie's width and height.Descriptionstring swfmovie->setdimensionint widthint heightswfmovie->setdimension sets the movie's width
to width and height to height.
SWFMovie->setframesSets the total number of frames in the animation.Descriptionstring swfmovie->setframesstring numberofframesswfmovie->setframes sets the total number of frames
in the animation to numberofframes.
SWFMovie->nextframeMoves to the next frame of the animation.Descriptionstring swfmovie->nextframevoid swfmovie->setframes moves to the next frame of
the animation.
SWFMovie->streammp3Streams a MP3 file.Descriptionstring swfmovie->streammp3string mp3FileNameswfmovie->streammp3 streams the mp3 file
mp3FileName. Not very robust in dealing with
oddities (can skip over an initial ID3 tag, but that's about it).
Like SWFShape::addJpegFill, this isn't a stable function- we'll
probably need to make a separate SWFSound object to contain sound types.
Note that the movie isn't smart enough to put enough frames in to contain
the entire mp3 stream- you'll have to add (length of song * frames per second)
frames to get the entire stream in.
Yes, now you can use ming to put that rock and roll devil worship music
into your SWF files. Just don't tell the RIAA.
swfmovie->streammp3 example
<?php
$m = new SWFMovie();
$m->setRate(12.0);
$m->streamMp3("distortobass.mp3");
// use your own MP3
// 11.85 seconds at 12.0 fps = 142 frames
$m->setFrames(142);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFDisplayItemCreates a new displayitem object.Descriptionnew swfdisplayitemvoidswfdisplayitem creates a new swfdisplayitem object.
Here's where all the animation takes place. After you define a shape,
a text object, a sprite, or a button, you add it to the movie, then use
the returned handle to move, rotate, scale, or skew the thing.
SWFDisplayItem has the following methods : swfdisplayitem->move,
swfdisplayitem->moveto, swfdisplayitem->scaleto,
swfdisplayitem->scale, swfdisplayitem->rotate,
swfdisplayitem->rotateto, swfdisplayitem->skewxto,
swfdisplayitem->skewx, swfdisplayitem->skewytoswfdisplayitem->skewyto, swfdisplayitem->setdepthswfdisplayitem->remove, swfdisplayitem->setnameswfdisplayitem->setratio, swfdisplayitem->addcolor
et swfdisplayitem->multcolor.
SWFDisplayItem->moveToMoves object in global coordinates.Descriptionbool swfdisplayitem->movetoint xint yswfdisplayitem->moveto moves the current object to
(x,y) in global coordinates.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->move.
SWFDisplayItem->moveMoves object in relative coordinates.Descriptionbool swfdisplayitem->moveint dxint dyswfdisplayitem->move moves the current object by
(dx,dy) from its
current position.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->moveto.
SWFDisplayItem->scaleToScales the object in global coordinates.Descriptionbool swfdisplayitem->scaletoint xint yswfdisplayitem->scaleto scales the current object to
(x,y) in global coordinates.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->scale.
SWFDisplayItem->scaleScales the object in relative coordinates.Descriptionbool swfdisplayitem->scaleint dxint dyswfdisplayitem->scale scales the current object by
(dx,dy) from its
current position.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->scaleto.
SWFDisplayItem->rotateToRotates the object in global coordinates.Descriptionbool swfdisplayitem->rotatetodouble degreesswfdisplayitem->rotateto set the current object
rotation to degrees degrees in global coordinates.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
This example bring three rotating string from the background to the
foreground. Pretty nice.
swfdisplayitem->rotateto example
<?php
$thetext = "ming!";
$f = new SWFFont("Bauhaus 93.fdb");
$m = new SWFMovie();
$m->setRate(24.0);
$m->setDimension(2400, 1600);
$m->setBackground(0xff, 0xff, 0xff);
// functions with huge numbers of arbitrary
// arguments are always a good idea! Really!
function text($r, $g, $b, $a, $rot, $x, $y, $scale, $string)
{
global $f, $m;
$t = new SWFText();
$t->setFont($f);
$t->setColor($r, $g, $b, $a);
$t->setHeight(960);
$t->moveTo(-($f->getWidth($string))/2, $f->getAscent()/2);
$t->addString($string);
// we can add properties just like a normal php var,
// as long as the names aren't already used.
// e.g., we can't set $i->scale, because that's a function
$i = $m->add($t);
$i->x = $x;
$i->y = $y;
$i->rot = $rot;
$i->s = $scale;
$i->rotateTo($rot);
$i->scale($scale, $scale);
// but the changes are local to the function, so we have to
// return the changed object. kinda weird..
return $i;
}
function step($i)
{
$oldrot = $i->rot;
$i->rot = 19*$i->rot/20;
$i->x = (19*$i->x + 1200)/20;
$i->y = (19*$i->y + 800)/20;
$i->s = (19*$i->s + 1.0)/20;
$i->rotateTo($i->rot);
$i->scaleTo($i->s, $i->s);
$i->moveTo($i->x, $i->y);
return $i;
}
// see? it sure paid off in legibility:
$i1 = text(0xff, 0x33, 0x33, 0xff, 900, 1200, 800, 0.03, $thetext);
$i2 = text(0x00, 0x33, 0xff, 0x7f, -560, 1200, 800, 0.04, $thetext);
$i3 = text(0xff, 0xff, 0xff, 0x9f, 180, 1200, 800, 0.001, $thetext);
for($i=1; $i<=100; ++$i)
{
$i1 = step($i1);
$i2 = step($i2);
$i3 = step($i3);
$m->nextFrame();
}
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
See also swfdisplayitem->rotate.
SWFDisplayItem->RotateRotates in relative coordinates.Descriptionbool swfdisplayitem->rotatedouble ddegreesswfdisplayitem->rotate rotates the current object
by ddegrees degrees from its current rotation.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->rotateto.
SWFDisplayItem->skewXToSets the X-skew.Descriptionbool swfdisplayitem->skewxtodouble degreesswfdisplayitem->skewxto sets the
x-skew to degrees. For degrees
is 1.0, it means a 45-degree forward slant. More is more forward,
less is more backward.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->skewx,
swfdisplayitem->skewy and
swfdisplayitem->skewyto.
SWFDisplayItem->skewXSets the X-skew.Descriptionbool swfdisplayitem->skewxdouble ddegreesswfdisplayitem->skewx adds ddegrees
to current x-skew.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->skewx,
swfdisplayitem->skewy and
swfdisplayitem->skewyto.
SWFDisplayItem->skewYToSets the Y-skew.Descriptionbool swfdisplayitem->skewytodouble degreesswfdisplayitem->skewyto sets the
y-skew to degrees. For degrees
is 1.0, it means a 45-degree forward slant. More is more upward,
less is more downward.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->skewy,
swfdisplayitem->skewx and
swfdisplayitem->skewxto.
SWFDisplayItem->skewYSets the Y-skew.Descriptionbool swfdisplayitem->skewydouble ddegreesswfdisplayitem->skewy adds ddegrees
to current y-skew.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfdisplayitem->skewyto,
swfdisplayitem->skewx and
swfdisplayitem->skewxto.
SWFDisplayItem->setDepthSets z-orderDescriptionbool swfdisplayitem->setdepthdouble depthswfdisplayitem->rotate sets the object's
z-order to depth. Depth defaults to the
order in which instances are created (by add'ing a shape/text to
a movie)- newer ones are on top of older ones. If two objects are
given the same depth, only the later-defined one can be moved.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
SWFDisplayItem->removeRemoves the object from the movieDescriptionbool swfdisplayitem->removevoidswfdisplayitem->remove removes this object from
the movie's display list.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
See also swfmovie->add.
SWFDisplayItem->setNameSets the object's nameDescriptionbool swfdisplayitem->setnamestring nameswfdisplayitem->setname sets the object's name to
name, for targetting with action script.
Only useful on sprites.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
SWFDisplayItem->setRatioSets the object's ratio to ratio.Descriptionvoid swfdisplayitem->setratiodouble ratioswfdisplayitem->setratio sets the object's ratio
to ratio. Obviously only useful for morphs.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
This simple example will morph nicely three concentric circles.
swfdisplayitem->setname example
<?php
$p = new SWFMorph();
$g = new SWFGradient();
$g->addEntry(0.0, 0, 0, 0);
$g->addEntry(0.16, 0xff, 0xff, 0xff);
$g->addEntry(0.32, 0, 0, 0);
$g->addEntry(0.48, 0xff, 0xff, 0xff);
$g->addEntry(0.64, 0, 0, 0);
$g->addEntry(0.80, 0xff, 0xff, 0xff);
$g->addEntry(1.00, 0, 0, 0);
$s = $p->getShape1();
$f = $s->addFill($g, SWFFILL_RADIAL_GRADIENT);
$f->scaleTo(0.05);
$s->setLeftFill($f);
$s->movePenTo(-160, -120);
$s->drawLine(320, 0);
$s->drawLine(0, 240);
$s->drawLine(-320, 0);
$s->drawLine(0, -240);
$g = new SWFGradient();
$g->addEntry(0.0, 0, 0, 0);
$g->addEntry(0.16, 0xff, 0, 0);
$g->addEntry(0.32, 0, 0, 0);
$g->addEntry(0.48, 0, 0xff, 0);
$g->addEntry(0.64, 0, 0, 0);
$g->addEntry(0.80, 0, 0, 0xff);
$g->addEntry(1.00, 0, 0, 0);
$s = $p->getShape2();
$f = $s->addFill($g, SWFFILL_RADIAL_GRADIENT);
$f->scaleTo(0.05);
$f->skewXTo(1.0);
$s->setLeftFill($f);
$s->movePenTo(-160, -120);
$s->drawLine(320, 0);
$s->drawLine(0, 240);
$s->drawLine(-320, 0);
$s->drawLine(0, -240);
$m = new SWFMovie();
$m->setDimension(320, 240);
$i = $m->add($p);
$i->moveTo(160, 120);
for($n=0; $n<=1.001; $n+=0.01)
{
$i->setRatio($n);
$m->nextFrame();
}
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFDisplayItem->addColorAdds the given color to this item's color transform.Descriptionbool swfdisplayitem->addcolorinteger redinteger greeninteger blueinteger aswfdisplayitem->addcolor adds the color to
this item's color transform. The color is given in its RGB form.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
SWFDisplayItem->multColorMultiplies the item's color transform.Descriptionbool swfdisplayitem->multcolorinteger redinteger greeninteger blueinteger aswfdisplayitem->multcolor multiplies the item's
color transform by the given values.
The object may be a swfshape, a
swfbutton, a swftext or a
swfsprite object. It must have been added using
the swfmovie->add.
This simple example will modify your picture's atmospher
to Halloween (use a landscape or bright picture).
swfdisplayitem->multcolor example
<?php
$b = new SWFBitmap("backyard.jpg");
// note use your own picture :-)
$s = new SWFShape();
$s->setRightFill($s->addFill($b));
$s->drawLine($b->getWidth(), 0);
$s->drawLine(0, $b->getHeight());
$s->drawLine(-$b->getWidth(), 0);
$s->drawLine(0, -$b->getHeight());
$m = new SWFMovie();
$m->setDimension($b->getWidth(), $b->getHeight());
$i = $m->add($s);
for($n=0; $n<=20; ++$n)
{
$i->multColor(1.0-$n/10, 1.0, 1.0);
$i->addColor(0xff*$n/20, 0, 0);
$m->nextFrame();
}
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFShapeCreates a new shape object.Descriptionnew swfshapevoidswfshape creates a new shape object.
SWFShape has the following methods : swfshape->setline,
swfshape->addfill, swfshape->setleftfile,
swfshape->setrightfile, swfshape->movepento,
swfshape->movepen, swfshape->drawlineto,
swfshape->drawline, swfshape->drawcurveto
et swfshape->drawcurve.
This simple example will draw a big red elliptic quadrant.
swfshape example
<?php
$s = new SWFShape();
$s->setLine(40, 0x7f, 0, 0);
$s->setRightFill($s->addFill(0xff, 0, 0));
$s->movePenTo(200, 200);
$s->drawLineTo(6200, 200);
$s->drawLineTo(6200, 4600);
$s->drawCurveTo(200, 4600, 200, 200);
$m = new SWFMovie();
$m->setDimension(6400, 4800);
$m->setRate(12.0);
$m->add($s);
$m->nextFrame();
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFShape->setLineSets the shape's line style.Descriptionbool swfshape->setlineint widthinteger redinteger greeninteger blueinteger aswfshape->setline sets the shape's line style.
width is the line's width. If width
is 0, the line's style is removed (then, all other arguments are ignored).
If width > 0, then line's color is set to
red, green, blue.
Last parameter a is optional.
swfshape->setline accepts 1, 4 or 5 arguments
(not 3 or 2).
You must declare all line styles before you use them (see example).
This simple example will draw a big "!#%*@", in funny colors and
gracious style.
swfshape->setline example
<?php
$s = new SWFShape();
$f1 = $s->addFill(0xff, 0, 0);
$f2 = $s->addFill(0xff, 0x7f, 0);
$f3 = $s->addFill(0xff, 0xff, 0);
$f4 = $s->addFill(0, 0xff, 0);
$f5 = $s->addFill(0, 0, 0xff);
// bug: have to declare all line styles before you use them
$s->setLine(40, 0x7f, 0, 0);
$s->setLine(40, 0x7f, 0x3f, 0);
$s->setLine(40, 0x7f, 0x7f, 0);
$s->setLine(40, 0, 0x7f, 0);
$s->setLine(40, 0, 0, 0x7f);
$f = new SWFFont('Techno.fdb');
$s->setRightFill($f1);
$s->setLine(40, 0x7f, 0, 0);
$s->drawGlyph($f, '!');
$s->movePen($f->getWidth('!'), 0);
$s->setRightFill($f2);
$s->setLine(40, 0x7f, 0x3f, 0);
$s->drawGlyph($f, '#');
$s->movePen($f->getWidth('#'), 0);
$s->setRightFill($f3);
$s->setLine(40, 0x7f, 0x7f, 0);
$s->drawGlyph($f, '%');
$s->movePen($f->getWidth('%'), 0);
$s->setRightFill($f4);
$s->setLine(40, 0, 0x7f, 0);
$s->drawGlyph($f, '*');
$s->movePen($f->getWidth('*'), 0);
$s->setRightFill($f5);
$s->setLine(40, 0, 0, 0x7f);
$s->drawGlyph($f, '@');
$m = new SWFMovie();
$m->setDimension(3000,2000);
$m->setRate(12.0);
$i = $m->add($s);
$i->moveTo(1500-$f->getWidth("!#%*@")/2, 1000+$f->getAscent()/2);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFShape->addFillAdds a solid fill to the shape.Descriptionstring swfshape->addfillinteger redinteger greeninteger blueinteger astring swfshape->addfillSWFbitmap bitmapinteger flagsstring swfshape->addfillSWFGradient gradientinteger flagsswfshape->addfill adds a solid fill to the shape's list
of fill styles. swfshape->addfill accepts three different
types of arguments.
red, green, blue
is a color (RGB mode). Last parameter a is optional.
The bitmap argument is an swfbitmap object.
The flags argument can be one
of the following values : SWFFILL_CLIPPED_BITMAP or SWFFILL_TILED_BITMAP.
Default is SWFFILL_TILED_BITMAP. I think.
The gradient argument is an swfgradient
object. The flags argument can be one of the following values :
SWFFILL_RADIAL_GRADIENT or SWFFILL_LINEAR_GRADIENT. Default is
SWFFILL_LINEAR_GRADIENT. I'm sure about this one. Really.
swfshape->addfill returns an swffill
object for use with the swfshape->setfill functions
described below.
See also swfshape->setfill.
This simple example will draw a frame on a bitmap. Ah, here's another buglet in
the flash player- it doesn't seem to care about the second shape's bitmap's
transformation in a morph. According to spec, the bitmap should stretch
along with the shape in this example..
swfshape->addfill example
<?php
$p = new SWFMorph();
$b = new SWFBitmap("alphafill.jpg");
// use your own bitmap
$width = $b->getWidth();
$height = $b->getHeight();
$s = $p->getShape1();
$f = $s->addFill($b, SWFFILL_TILED_BITMAP);
$f->moveTo(-$width/2, -$height/4);
$f->scaleTo(1.0, 0.5);
$s->setLeftFill($f);
$s->movePenTo(-$width/2, -$height/4);
$s->drawLine($width, 0);
$s->drawLine(0, $height/2);
$s->drawLine(-$width, 0);
$s->drawLine(0, -$height/2);
$s = $p->getShape2();
$f = $s->addFill($b, SWFFILL_TILED_BITMAP);
// these two have no effect!
$f->moveTo(-$width/4, -$height/2);
$f->scaleTo(0.5, 1.0);
$s->setLeftFill($f);
$s->movePenTo(-$width/4, -$height/2);
$s->drawLine($width/2, 0);
$s->drawLine(0, $height);
$s->drawLine(-$width/2, 0);
$s->drawLine(0, -$height);
$m = new SWFMovie();
$m->setDimension($width, $height);
$i = $m->add($p);
$i->moveTo($width/2, $height/2);
for($n=0; $n<1.001; $n+=0.03)
{
$i->setRatio($n);
$m->nextFrame();
}
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFShape->setLeftFillSets left rasterizing color.Descriptionstring swfshape->setleftfillswfgradient fillstring swfshape->setleftfillinteger redinteger greeninteger blueinteger a
What this nonsense is about is, every edge segment borders at most two fills.
When rasterizing the object, it's pretty handy to know what those fills are
ahead of time, so the swf format requires these to be specified.
swfshape->setleftfill sets the fill on the left side of
the edge- that is, on the interior if you're defining the outline of the shape in a counter-clockwise
fashion. The fill object is an SWFFill object returned from one of the addFill
functions above.
This seems to be reversed when you're defining a shape in a morph, though.
If your browser crashes, just try setting the fill on the other side.
Shortcut for swfshape->setleftfill($s->addfill($r, $g, $b [, $a]));.
See also swfshape->setrightfill.
SWFShape->setRightFillSets right rasterizing color.Descriptionstring swfshape->setrightfillswfgradient fillstring swfshape->setrightfillinteger redinteger greeninteger blueinteger a
See also swfshape->setleftfill.
Shortcut for swfshape->setrightfill($s->addfill($r, $g, $b [, $a]));.
SWFShape->movePenToMoves the shape's pen.Descriptionstring swfshape->movepentointeger xinteger yswfshape->setrightfill move the shape's pen to
(x,y) in the shape's
coordinate space.
See also
swfshape->movepen,
swfshape->drawcurveto,
swfshape->drawlineto et
swfshape->drawline.
SWFShape->movePenMoves the shape's pen (relative).Descriptionstring swfshape->movepeninteger dxinteger dyswfshape->setrightfill move the shape's pen from
coordinates (current x,current y) to (current x + dx,
current y + dy) in the shape's coordinate space.
See also
swfshape->movepento,
swfshape->drawcurveto,
swfshape->drawlineto et
swfshape->drawline.
SWFShape->drawLineToDraws a line.Descriptionstring swfshape->drawlinetointeger xinteger yswfshape->setrightfill draws a line (using the
current line style, set by swfshape->setline) from the current
pen position to point (x,y)
in the shape's coordinate space.
See also
swfshape->movepento,
swfshape->drawcurveto,
swfshape->movepen et
swfshape->drawline.
SWFShape->drawLineDraws a line (relative).Descriptionstring swfshape->drawlineinteger dxinteger dyswfshape->setrightfill draws a line (using the current line style
set by swfshape->setline) from the current pen position to
displacement (dx,dy).
See also
swfshape->movepento,
swfshape->drawcurveto,
swfshape->movepen et
swfshape->drawlineto.
SWFShape->drawCurveToDraws a curve.Descriptionstring swfshape->drawcurvetointeger controlxinteger controlyinteger anchorxinteger anchoryswfshape->drawcurveto draws a quadratic curve
(using the current line style, set by swfshape->setline)
from the current pen position to
(anchorx,anchory)
using (controlx,controly)
as a control point. That is, head towards the control point,
then smoothly turn to the anchor point.
See also
swfshape->drawlineto,
swfshape->drawline,
swfshape->movepento et
swfshape->movepen.
SWFShape->drawCurveDraws a curve (relative).Descriptionstring swfshape->drawcurveinteger controldxinteger controldyinteger anchordxinteger anchordyswfshape->drawcurve draws a quadratic curve
(using the current line style,set by swfshape->setline)
from the current pen position to the relative position
(anchorx,anchory)
using relative control point
(controlx,controly).
That is, head towards the control point, then smoothly turn to the
anchor point.
See also
swfshape->drawlineto,
swfshape->drawline,
swfshape->movepento et
swfshape->movepen.
SWFGradientLoads a font definitionDescriptionnew swfgradientvoidswfgradient creates a new SWFGradient object.
After you've added the entries to your gradient, you can use the gradient
in a shape fill with the swfshape->addfill method.
SWFGradient has the following methods : swfgradient->addentry.
This simple example will draw a big black-to-white gradient as background,
and a redish disc in its center.
swfgradient example
<?php
$m = new SWFMovie();
$m->setDimension(320, 240);
$s = new SWFShape();
// first gradient- black to white
$g = new SWFGradient();
$g->addEntry(0.0, 0, 0, 0);
$g->addEntry(1.0, 0xff, 0xff, 0xff);
$f = $s->addFill($g, SWFFILL_LINEAR_GRADIENT);
$f->scaleTo(0.01);
$f->moveTo(160, 120);
$s->setRightFill($f);
$s->drawLine(320, 0);
$s->drawLine(0, 240);
$s->drawLine(-320, 0);
$s->drawLine(0, -240);
$m->add($s);
$s = new SWFShape();
// second gradient- radial gradient from red to transparent
$g = new SWFGradient();
$g->addEntry(0.0, 0xff, 0, 0, 0xff);
$g->addEntry(1.0, 0xff, 0, 0, 0);
$f = $s->addFill($g, SWFFILL_RADIAL_GRADIENT);
$f->scaleTo(0.005);
$f->moveTo(160, 120);
$s->setRightFill($f);
$s->drawLine(320, 0);
$s->drawLine(0, 240);
$s->drawLine(-320, 0);
$s->drawLine(0, -240);
$m->add($s);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFGradient->addEntryAdds an entry to the gradient list.Descriptionstring swfgradient->addentrydouble ratiointeger redinteger greeninteger blueinteger aswfgradient->addentry adds an entry to the gradient list.
ratio is a number between 0 and 1 indicating where in
the gradient this color appears. Thou shalt add entries in order of increasing ratio.
red, green, blue
is a color (RGB mode). Last parameter a is optional.
SWFBitmapLoads Bitmap objectDescriptionnew swfbitmapstring filenameinteger alphafilenameswfbitmap creates a new SWFBitmap object from
the Jpeg or DBL file named filename.
alphafilename indicates a MSK file to
be used as an alpha mask for a Jpeg image.
We can only deal with baseline (frame 0) jpegs, no baseline optimized or
progressive scan jpegs!
SWFBitmap has the following methods : swfbitmap->getwidth
and swfbitmap->getheight.
You can't import png images directly, though- have to use the png2dbl
utility to make a dbl ("define bits lossless") file from the png.
The reason for this is that I don't want a dependency on the png library
in ming- autoconf should solve this, but that's not set up yet.
Import PNG files
<?php
$s = new SWFShape();
$f = $s->addFill(new SWFBitmap("png.dbl"));
$s->setRightFill($f);
$s->drawLine(32, 0);
$s->drawLine(0, 32);
$s->drawLine(-32, 0);
$s->drawLine(0, -32);
$m = new SWFMovie();
$m->setDimension(32, 32);
$m->add($s);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
And you can put an alpha mask on a jpeg fill.
swfbitmap example
<?php
$s = new SWFShape();
// .msk file generated with "gif2mask" utility
$f = $s->addFill(new SWFBitmap("alphafill.jpg", "alphafill.msk"));
$s->setRightFill($f);
$s->drawLine(640, 0);
$s->drawLine(0, 480);
$s->drawLine(-640, 0);
$s->drawLine(0, -480);
$c = new SWFShape();
$c->setRightFill($c->addFill(0x99, 0x99, 0x99));
$c->drawLine(40, 0);
$c->drawLine(0, 40);
$c->drawLine(-40, 0);
$c->drawLine(0, -40);
$m = new SWFMovie();
$m->setDimension(640, 480);
$m->setBackground(0xcc, 0xcc, 0xcc);
// draw checkerboard background
for($y=0; $y<480; $y+=40)
{
for($x=0; $x<640; $x+=80)
{
$i = $m->add($c);
$i->moveTo($x, $y);
}
$y+=40;
for($x=40; $x<640; $x+=80)
{
$i = $m->add($c);
$i->moveTo($x, $y);
}
}
$m->add($s);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFBitmap->getWidthReturns the bitmap's width.Descriptionint swfbitmap->getwidthvoidswfbitmap->getwidth returns the bitmap's width in pixels.
See also swfbitmap->getheight.
SWFBitmap->getHeightReturns the bitmap's height.Descriptionint swfbitmap->getheightvoidswfbitmap->getheight returns the bitmap's height in pixels.
See also swfbitmap->getwidth.
SWFFillLoads SWFFill objectDescription
The swffill object allows you to transform
(scale, skew, rotate) bitmap and gradient fills. swffill
objects are created by the swfshape->addfill methods.
SWFFill has the following methods : swffill->moveto
and swffill->scaleto, swffill->rotateto,
swffill->skewxto and swffill->skewyto.
SWFFill->moveToMoves fill originDescriptionint swffill->movetointeger xinteger yswffill->moveto moves fill's origin to
(x,y) in global coordinates.
SWFFill->scaleToSets fill's scaleDescriptionint swffill->scaletointeger xinteger yswffill->scaleto sets fill's scale to
x in the x-direction,
y in the y-direction.
SWFFill->rotateToSets fill's rotationDescriptionint swffill->rotatetodouble degreesswffill->rotateto sets fill's rotation to
degrees degrees.
SWFFill->skewXToSets fill x-skewDescriptionint swffill->skewxtodouble xswffill->skewxto sets fill x-skew to x.
For x is 1.0, it is a is a 45-degree
forward slant. More is more forward, less is more backward.
SWFFill->skewYToSets fill y-skewDescriptionint swffill->skewytodouble yswffill->skewyto sets fill y-skew to y.
For y is 1.0, it is a is a 45-degree
upward slant. More is more upward, less is more downward.
SWFMorphCreates a new SWFMorph object.Descriptionnew swfmorphvoidswfmorph creates a new SWFMorph object.
Also called a "shape tween". This thing lets you make those tacky
twisting things that make your computer choke. Oh, joy!
The methods here are sort of weird. It would make more sense to just
have newSWFMorph(shape1, shape2);, but as things are now, shape2 needs
to know that it's the second part of a morph. (This, because it starts
writing its output as soon as it gets drawing commands- if it kept its
own description of its shapes and wrote on completion this and some
other things would be much easier.)
SWFMorph has the following methods : swfmorph->getshape1
and swfmorph->getshape1.
This simple example will morph a big red square into a smaller
blue black-bordered square.
swfmorph example
<?php
$p = new SWFMorph();
$s = $p->getShape1();
$s->setLine(0,0,0,0);
/* Note that this is backwards from normal shapes (left instead of right).
I have no idea why, but this seems to work.. */
$s->setLeftFill($s->addFill(0xff, 0, 0));
$s->movePenTo(-1000,-1000);
$s->drawLine(2000,0);
$s->drawLine(0,2000);
$s->drawLine(-2000,0);
$s->drawLine(0,-2000);
$s = $p->getShape2();
$s->setLine(60,0,0,0);
$s->setLeftFill($s->addFill(0, 0, 0xff));
$s->movePenTo(0,-1000);
$s->drawLine(1000,1000);
$s->drawLine(-1000,1000);
$s->drawLine(-1000,-1000);
$s->drawLine(1000,-1000);
$m = new SWFMovie();
$m->setDimension(3000,2000);
$m->setBackground(0xff, 0xff, 0xff);
$i = $m->add($p);
$i->moveTo(1500,1000);
for($r=0.0; $r<=1.0; $r+=0.1)
{
$i->setRatio($r);
$m->nextFrame();
}
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFMorph->getshape1Gets a handle to the starting shapeDescriptionint swfmorph->getshape1voidswfmorph->getshape1 gets a handle to the morph's
starting shape. swfmorph->getshape1 returns an
swfshape object.
SWFMorph->getshape2Gets a handle to the ending shapeDescriptionint swfmorph->getshape2voidswfmorph->getshape2 gets a handle to the morph's
ending shape. swfmorph->getshape2 returns an
swfshape object.
SWFMorphCreates a new SWFText object.Descriptionnew swftextvoidswftext creates a new SWFText object,
fresh for manipulating.
SWFText has the following methods : swftext->setfont,
swftext->setheight, swftext->setspacing,
swftext->setcolor, swftext->moveto,
swftext->addstring and swftext->getwidth.
This simple example will draw a big yellow "PHP generates Flash with Ming"
text, on white background.
swftext example
<?php
$f = new SWFFont("Techno.fdb");
$t = new SWFText();
$t->setFont($f);
$t->moveTo(200, 2400);
$t->setColor(0xff, 0xff, 0);
$t->setHeight(1200);
$t->addString("PHP generates Flash with Ming!!");
$m = new SWFMovie();
$m->setDimension(5400, 3600);
$m->add($t);
header('Content-type: application/x-shockwave-flash');
$m->output();
?>
SWFText->setFontSets the current fontDescriptionint swftext->setfontstring fontswftext->setfont sets the current font to
font.
SWFText->setHeightSets the current font heighDescriptionint swftext->setheightinteger heightswftext->setheight sets the current font height to
height. Default is 240.
SWFText->setSpacingSets the current font spacingDescriptionint swftext->setspacingdouble spacingswftext->setspacing sets the current font spacing to
spacingspacing. Default is 1.0.
0 is all of the letters written at the same point. This doesn't really work
that well because it inflates the advance across the letter, doesn't add
the same amount of spacing between the letters. I should try and explain
that better, prolly. Or just fix the damn thing to do constant spacing.
This was really just a way to figure out how letter advances work,
anyway.. So nyah.
SWFText->setColorSets the current font heighDescriptionint swftext->setcolorinteger redinteger greeninteger blueinteger aswftext->setspacing changes the current text color.
Default is black. I think. Color is represented using the RGB system.
SWFText->moveToMoves the penDescriptionint swftext->movetointeger xinteger yswftext->moveto moves the pen (or cursor, if
that makes more sense) to (x,y)
in text object's coordinate space. If either is zero, though, value
in that dimension stays the same. Annoying, should be fixed.
SWFText->addStringDraws a stringDescriptionint swftext->addstringstring stringswftext->addstring draws the string string
at the current pen (cursor) location. Pen is at the baseline of the text;
i.e., ascending text is in the -y direction.
SWFText->getWidthComputes string's widthDescriptionint swftext->addstringstring stringswftext->addstring returns the rendered width of the
string string at the text object's current font,
scale, and spacing settings.
SWFFontLoads a font definitionDescriptionnew swffontstring filename
If name is the name of an FDB file (i.e., it ends in ".fdb"), load the font
definition found in said file. Otherwise, create a browser-defined font reference.
FDB ("font definition block") is a very simple wrapper for the SWF DefineFont2
block which contains a full description of a font. One may create FDB files from
SWT Generator template files with the included makefdb utility- look in the
util directory off the main ming distribution directory.
Browser-defined fonts don't contain any information about the font other
than its name. It is assumed that the font definition will be provided by
the movie player. The fonts _serif, _sans, and _typewriter should always
be available. For example:
<?php
$f = newSWFFont("_sans");
?>
will give you the standard sans-serif font, probably the same as what you'd get
with <font name="sans-serif"> in HTML.
Returns a reference to the font definition, for use in the SWFText setFont method
and the SWFTextField setFont method.
SWFFont has the following methods : swffont->getwidth.
getwidthReturns the string's widthDescriptionstring swffont->getwidthstring stringnom_de_la_fonction returns the string
string's width, using font's default scaling.
You'll probably want to use the SWFText version of this method which
uses the text object's scale.
SWFTextFieldCreates a text field objectDescriptionnew swftextfieldint flagsswftextfield creates a new text field object.
Text Fields are less flexible than swftext objects-
they can't be rotated, scaled non-proportionally, or skewed, but they can
be used as form entries, and they can use browser-defined fonts.
The optional flags change the text field's behavior. It has the following
possibles values :
SWFTEXTFIELD_NOEDIT : indicates that the field shouldn't be user-editable
SWFTEXTFIELD_PASSWORD obscures the data entry
SWFTEXTFIELD_DRAWBOX draws the outline of the textfield
SWFTEXTFIELD_MULTILINE allows multiple lines
SWFTEXTFIELD_WORDWRAP allows text to wrap
SWFTEXTFIELD_NOSELECT makes the field non-selectable
Flags are combined with the bitwise OR operation. For example,
<?php
$t = newSWFTextField(SWFTEXTFIELD_PASSWORD | SWFTEXTFIELD_NOEDIT);
?>
creates a totally useless non-editable password field.
SWFTextField has the following methods : swftextfield->setfont,
swftextfield->setbounds, swftextfield->align,
swftextfield->setheight, swftextfield->setleftmargin,
swftextfield->setrightmargin, swftextfield->setmargins,
swftextfield->setindentation, swftextfield->setlinespacing,
swftextfield->setcolor, swftextfield->setname et
swftextfield->addstring.
SWFTextField->setFontSets the text field fontDescriptionint swftextfield->setfontstring fontswftextfield->setfont sets the text field font to
the [browser-defined?] font font.
SWFTextField->setboundsSets the text field width and heightDescriptionint swftextfield->setboundsint widthint heightswftextfield->setbounds sets the text field width
to width and height to height.
If you don't set the bounds yourself, Ming makes a poor guess at what
the bounds are.
SWFTextField->alignSets the text field width and heightDescriptionint swftextfield->alignint alignementswftextfield->align sets the text field alignment
to alignement. Valid values for
alignement are: SWFTEXTFIELD_ALIGN_LEFT,
SWFTEXTFIELD_ALIGN_RIGHT, SWFTEXTFIELD_ALIGN_CENTER and
SWFTEXTFIELD_ALIGN_JUSTIFY.
SWFTextField->setHeightSets the font height of this text field font.Descriptionint swftextfield->setheightint heightswftextfield->setheight sets the font height of this text field
font to the given height height. Default is 240.
SWFTextField->setLeftMarginSets the left margin width of the text field.Descriptionint swftextfield->setleftmarginint widthswftextfield->setleftmargin sets the left margin width
of the text field to width. Default is 0.
SWFTextField->setrightMarginSets the right margin width of the text field.Descriptionint swftextfield->setrightmarginint widthswftextfield->setrightmargin sets the right margin width
of the text field to width. Default is 0.
SWFTextField->setMarginsSets the margins width of the text field.Descriptionint swftextfield->setmarginsint leftint rightswftextfield->setmargins set both margins at once,
for the man on the go.
SWFTextField->setindentationSets the indentation of the first line.Descriptionint swftextfield->setindentationint widthswftextfield->setindentation sets the indentation of
the first line in the text field, to width.
SWFTextField->setLineSpacingSets the line spacing of the text field.Descriptionint swftextfield->setlinespacingint heightswftextfield->setlinespacing sets the line spacing
of the text field to the height of height. Default is 40.
SWFTextField->setcolorSets the color of the text field. Descriptionint swftextfield->setcolorinteger redinteger greeninteger blueinteger aswftextfield->setcolor sets the color of the text field.
Default is fully opaque black. Color is represented using RGB system.
SWFTextField->setnameSets the variable nameDescriptionint swftextfield->setnamestring nameswftextfield->setname sets the variable name of this
text field to name, for form posting and action
scripting purposes.
SWFTextField->addstringConcatenates the given string to the text fieldDescriptionint swftextfield->addstringstring stringswftextfield->setname concatenates the string
string to the text field.
SWFSpriteCreates a movie clip (a sprite)Descriptionnew swfspritevoid
SWFSprite are also known as a "movie clip", this allows one to create objects
which are animated in their own timelines. Hence, the sprite has most of the
same methods as the movie.
SWFSprite has the following methods : swfsprite->add,
swfsprite->remove, swfsprite->nextframeswfsprite->setframes.
This simple example will spin gracefully a big