Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg

PHP : Function Reference : Ming functions for Flash

Ming functions for Flash


This extension is EXPERIMENTAL. The behaviour of this extension -- including the names of its functions and anything else documented about this extension -- may change without notice in a future release of PHP. Use this extension at your own risk.


First of all: Ming is not an acronym. 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.

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 at »

Ming was added in PHP 4.0.5.


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: » 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 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.


Example 1331. built into PHP (Unix)

    mkdir <phpdir>/ext/ming
    cp php_ext/* <phpdir>/ext/ming
    cd <phpdir>
    ./configure --with-ming <other config options>


Build and install PHP as usual, restart web server if necessary.

Now either just add to your php.ini file, or put dl(''); at the head of all of your Ming scripts.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

Predefined Constants

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

MING_NEW (integer)
MING_ZLIB (integer)
SWFBUTTON_UP (integer)

Predefined Classes

The classes below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

Table of Contents

SWFAction — SWFAction Class
SWFAction->__construct() — Creates a new SWFAction
SWFBitmap — SWFBitmap Class
SWFBitmap->__construct() — Loads Bitmap object
SWFBitmap->getHeight() — Returns the bitmap's height
SWFBitmap->getWidth() — Returns the bitmap's width
SWFButton — SWFButton Class
SWFButton->__construct() — Creates a new Button
SWFButton->addAction() — Adds an action
SWFButton->addASound() — Associates a sound with a button transition
SWFButton->addShape() — Adds a shape to a button
SWFButton->setAction() — Sets the action
SWFButton->setDown() — Alias for addShape(shape, SWFBUTTON_DOWN)
SWFButton->setHit() — Alias for addShape(shape, SWFBUTTON_HIT)
SWFButton->setMenu() — enable track as menu button behaviour
SWFButton->setOver() — Alias for addShape(shape, SWFBUTTON_OVER)
SWFButton->setUp() — Alias for addShape(shape, SWFBUTTON_UP)
SWFDisplayItem — SWFDisplayItem Class
SWFDisplayItem->addAction() — Adds this SWFAction to the given SWFSprite instance
SWFDisplayItem->addColor() — Adds the given color to this item's color transform
SWFDisplayItem->endMask() — Another way of defining a MASK layer
SWFDisplayItem->move() — Moves object in relative coordinates
SWFDisplayItem->moveTo() — Moves object in global coordinates
SWFDisplayItem->multColor() — Multiplies the item's color transform
SWFDisplayItem->remove() — Removes the object from the movie
SWFDisplayItem->rotate() — Rotates in relative coordinates
SWFDisplayItem->rotateTo() — Rotates the object in global coordinates
SWFDisplayItem->scale() — Scales the object in relative coordinates
SWFDisplayItem->scaleTo() — Scales the object in global coordinates
SWFDisplayItem->setDepth() — Sets z-order
SWFDisplayItem->setMaskLevel() — Defines a MASK layer at level
SWFDisplayItem->setMatrix() — Sets the item's transform matrix
SWFDisplayItem->setName() — Sets the object's name
SWFDisplayItem->setRatio() — Sets the object's ratio
SWFDisplayItem->skewX() — Sets the X-skew
SWFDisplayItem->skewXTo() — Sets the X-skew
SWFDisplayItem->skewY() — Sets the Y-skew
SWFDisplayItem->skewYTo() — Sets the Y-skew
SWFFill — SWFFill Class
SWFFill->moveTo() — Moves fill origin
SWFFill->rotateTo() — Sets fill's rotation
SWFFill->scaleTo() — Sets fill's scale
SWFFill->skewXTo() — Sets fill x-skew
SWFFill->skewYTo() — Sets fill y-skew
SWFFont — SWFFont Class
SWFFont->__construct() — Loads a font definition
SWFFont->getAscent() — Returns the ascent of the font, or 0 if not available
SWFFont->getDescent() — Returns the descent of the font, or 0 if not available
SWFFont->getLeading() — Returns the leading of the font, or 0 if not available
SWFFont->getShape() — Returns the glyph shape of a char as a text string
SWFFont->getUTF8Width() — Calculates the width of the given string in this font at full height
SWFFont->getWidth() — Returns the string's width
SWFFontChar — SWFFontChar Class
SWFFontChar->addChars() — Adds characters to a font for exporting font
SWFFontChar->addUTF8Chars() — Adds characters to a font for exporting font
SWFGradient — SWFGradient Class
SWFGradient->__construct() — Creates a gradient object
SWFGradient->addEntry() — Adds an entry to the gradient list
SWFMorph — SWFMorph Class
SWFMorph->__construct() — Creates a new SWFMorph object
SWFMorph->getShape1() — Gets a handle to the starting shape
SWFMorph->getShape2() — Gets a handle to the ending shape
SWFMovie — SWFMovie Class
SWFMovie->__construct() — Creates a new movie object, representing an SWF version 4 movie
SWFMovie->add() — Adds any type of data to a movie
SWFMovie->labelFrame() — Labels a frame
SWFMovie->nextFrame() — Moves to the next frame of the animation
SWFMovie->output() — Dumps your lovingly prepared movie out
SWFMovie->remove() — Removes the object instance from the display list
SWFMovie->save() — Saves the SWF movie in a file
SWFMovie->setbackground() — Sets the background color
SWFMovie->setDimension() — Sets the movie's width and height
SWFMovie->setFrames() — Sets the total number of frames in the animation
SWFMovie->setRate() — Sets the animation's frame rate
SWFMovie->streamMP3() — Streams a MP3 file
SWFPrebuiltClip — SWFPrebuiltClip Class
SWFPrebuiltClip->__construct() — Returns a SWFPrebuiltClip object
SWFShape — SWFShape Class
SWFShape->__construct() — Creates a new shape object
SWFShape->addFill() — Adds a solid fill to the shape
SWFShape->drawArc() — Draws an arc of radius r centered at the current location, from angle startAngle to angle endAngle measured clockwise from 12 o'clock
SWFShape->drawCircle() — Draws a circle of radius r centered at the current location, in a counter-clockwise fashion
SWFShape->drawCubic() — Draws a cubic bezier curve using the current position and the three given points as control points
SWFShape->drawCubicTo() — Draws a cubic bezier curve using the current position and the three given points as control points
SWFShape->drawCurve() — Draws a curve (relative)
SWFShape->drawCurveTo() — Draws a curve
SWFShape->drawGlyph() — Draws the first character in the given string into the shape using the glyph definition from the given font
SWFShape->drawLine() — Draws a line (relative)
SWFShape->drawLineTo() — Draws a line
SWFShape->movePen() — Moves the shape's pen (relative)
SWFShape->movePenTo() — Moves the shape's pen
SWFShape->setLeftFill() — Sets left rasterizing color
SWFShape->setLine() — Sets the shape's line style
SWFShape->setRightFill() — Sets right rasterizing color
SWFSound — SWFSound Class
SWFSound — Returns a new SWFSound object from given file
SWFSoundInstance — SWFSoundInstance Class
SWFSprite — SWFSprite Class
SWFSprite->__construct() — Creates a movie clip (a sprite)
SWFSprite->add() — Adds an object to a sprite
SWFSprite->labelFrame() — Labels frame
SWFSprite->nextFrame() — Moves to the next frame of the animation
SWFSprite->remove() — Removes an object to a sprite
SWFSprite->setFrames() — Sets the total number of frames in the animation
SWFText — SWFText Class
SWFText->__construct() — Creates a new SWFText object
SWFText->addString() — Draws a string
SWFText->addUTF8String() — Writes the given text into this SWFText object at the current pen position, using the current font, height, spacing, and color
SWFText->getAscent() — Returns the ascent of the current font at its current size, or 0 if not available
SWFText->getDescent() — Returns the descent of the current font at its current size, or 0 if not available
SWFText->getLeading() — Returns the leading of the current font at its current size, or 0 if not available
SWFText->getUTF8Width() — calculates the width of the given string in this text objects current font and size
SWFText->getWidth() — Computes string's width
SWFText->moveTo() — Moves the pen
SWFText->setColor() — Sets the current text color
SWFText->setFont() — Sets the current font
SWFText->setHeight() — Sets the current font height
SWFText->setSpacing() — Sets the current font spacing
SWFTextField — SWFTextField Class
SWFTextField->__construct() — Creates a text field object
SWFTextField->addChars() — adds characters to a font that will be available within a textfield
SWFTextField->addString() — Concatenates the given string to the text field
SWFTextField->align() — Sets the text field alignment
SWFTextField->setBounds() — Sets the text field width and height
SWFTextField->setColor() — Sets the color of the text field
SWFTextField->setFont() — Sets the text field font
SWFTextField->setHeight() — Sets the font height of this text field font
SWFTextField->setIndentation() — Sets the indentation of the first line
SWFTextField->setLeftMargin() — Sets the left margin width of the text field
SWFTextField->setLineSpacing() — Sets the line spacing of the text field
SWFTextField->setMargins() — Sets the margins width of the text field
SWFTextField->setName() — Sets the variable name
SWFTextField->setPadding() — Sets the padding of this textfield
SWFTextField->setRightMargin() — Sets the right margin width of the text field
SWFVideoStream — SWFVideoStream Class
SWFVideoStream->__construct() — Returns a SWFVideoStream object
ming_keypress — Returns the action flag for keyPress(char)
ming_setcubicthreshold — Set cubic threshold
ming_setscale — Set scale
ming_setswfcompression — Sets the SWF output compression
ming_useconstants — Use constant pool
ming_useswfversion — Sets the SWF version

Code Examples / Notes » ref.ming


You can get several .fdb font files from


The current CVS version, Ming 0.3a, supports
a lot of MX ActionScript including the MX Drawing API.
This is very nice for easy command line compiling of
MX ActionScript only movies.
For example:
$movie = new SWFMovie();
$movie->setBackground(0xcc, 0xcc, 0xcc );
// mx actionscript
$strAction = "
_root.createEmptyMovieClip ( 'triangle', 1 );
with ( _root.triangle ) {
lineStyle( 5, 0xff00ff, 100 );
moveTo( 200, 200 );
lineTo( 300,300 );
lineTo( 100, 300 );
lineTo( 200, 200 );
$movie->add(new SWFAction( str_replace("\r", "", $strAction) ));
Lots of examples here:


I tried to use the code suggested below by random at nowhere dot com to extract the width and height from an swf with no success, however the following worked for me in php 5.
$info = getimagesize('flashfile.swf');
$w = $info[0];
$h = $info[1];
not sure how far back it works, or with what versions of flash, but it seems to work with flash 7 files just fine.


Here is a little font browser I made to try and typeset match my designers font from the pack of 1300+ fdb I found on google:
$m = new SWFMovie();
$m->setBackground(0xFF, 0xFF, 0xFF);
$m->setDimension(320, 40);
function drawGlyphString($string, $s, $f, $fill) {
$s->movePenTo(0, $f->getAscent());
for ($i=0; $i<strlen($string); $i++) {
$s->drawGlyph($f, substr($string,$i,1), $size);
$s->movePen($f->getWidth(substr($string,$i,1)), 0);

function drawFont($f) {
$logo = new SWFShape();
$grey = $logo->addFill(0, 0, 0);
drawGlyphString('yrt '.$_REQUEST['fdb'], $logo, $f, $grey);
return $logo;

if ($_REQUEST['fdb']) {
$f = new SWFFont($_REQUEST['fdb']);
$i = $m->add(drawFont($f));
header('Content-type: application/x-shockwave-flash');
} else {
if (!$_REQUEST['o']) $_REQUEST['o']=0;
if (!$_REQUEST['l']) $_REQUEST['l']=80;
$d = dir(".");
while (false !== ($entry = $d->read())) {
if (stristr($entry, 'fdb') && !strstr($entry, '-I') && !strstr($entry, '-B')) {
if ($_REQUEST['o']) {
} elseif ($_REQUEST['l'] ) {
echo '<iframe height="30px" src="fonts.php?fdb='.$entry.'&" title="'.$entry.'"></iframe>';
} else {
echo '<img src="/">
<a href="?l='.$l.'&o='.($o+$l).'">next ></a>';exit;



For those who don't get the naming, _Ming_ the Merciless was comic book hero _Flash_ Gordon's arch enemy.


For those looking for just getting size of a .swf file :
// bytes_to_signed_int(data,offset,length)
function b2i($d,$o,$l) {
$s=(ord($d[$o/8])>>(7-$o%8))&1; $r=0;
for ($i=$o+1;$i<$o+$l;$i++) {
if ($s) { $r++; $r=-$r; }
return $r;
// flash9 or <9 but uncompressed
// get only 20 first bytes
echo "Version of Flash : ".ord($d[3])."
$s=unpack("V",substr($d,4,4)); echo "FileSize : ".$s[1]." bytes
// here is the decompression, fix this for flash <9
if (substr($d,0,3)=="CWS") $d=substr($d,0,8).gzinflate(substr($d,8));
$nb=ord($d[8])>>3; // bytes needed
// width=xmax-xmin, height=ymax-ymin, twips->pixels = /20
echo "width=".(($xmax-$xmin)/20)."
echo "height=".(($ymax-$ymin)/20)."


For People Like My Mate, Matt, Who Dosent Know Much PHP, I Am Creating A Simpeler PHP Libary. It Runs Under Ming 0.3
It - Along With Two Examples - Can Be Currently Downloaded From The Link Below
PLEASE NOTE : At The Time Of This Post, The Libary Is Currently Is Unfinished And Currently Looks Like A Mess Of Files - But It Works!


//In quicktime, movies may be exported as jpeg or png
//This object will convert any movie that has been saved as a group of images into
//an swf file. The frame rate and other attributes can be controlled
$path = "my_movie_dir"; //relative path to the jpg/png or bmp files
$frame_rate=30; //frame rate of the flash movie
$quality=50; //image quality during conversion (only valid if not jpeg)
$skip_rate=5; //how many frames to skip
set_time_limit("600"); //this could take some time
$converter=new images_to_swf($path,$frame_rate,$skip_rate);
//$converter->convert_images(70); //Use this if using non jpeg files or decreasing the quality
$converter->make_movie();//Make the movie
//Do two things with it
class images_to_swf {

var $path; //path to the image files
var $skip_rate;
var $movie;
var $images=array();

function images_to_swf($path,$frame_rate=30,$skip_rate=5) {

$this->movie=new swfmovie ();
$this->movie->setrate ($frame_rate);

function convert_images($quality=80,$delete_old_files=1) {
$main = opendir($this->path);
//first convert to jpeg (if we have to)
//also change the quality
while($filename = readdir($main)) {

//only use valid file types
if (ereg("(png|bmp|jpg|jpeg)\$",$filename)) {

if (ereg("png\$",$filename)) $temp_img=imagecreatefrompng ($file_path);
else if (ereg("bmp\$",$filename)) $temp_img=imagecreatefrompng ($file_path);
else if (ereg("(jpg|jpeg)\$",$filename)) $temp_img=imagecreatefromjpeg ($file_path);

if (ereg("(png|bmp)\$",$filename)) {
if ($delete_old_files) unlink($file_path);
else $new_file_path=$file_path;


//echo "Converted $filename to $new_file_path at quality $quality<br />";

function make_movie() {
$main = opendir($this->path);
//Get all valid jpegs
while($filename = readdir($main)) {
if (ereg("(jpg|jpeg)\$",$filename)) {

//Put jpegs in order

//then create the movie
for ($a=0; $a<count($valid_paths); $a=$a+$this->skip_rate) {
$fp = fopen($valid_paths[$a],"rb");
$this->images[$a] = fread($fp,999999);
$this->movie->add(new swfbitmap($this->images[$a]));
//echo "Added ".$valid_paths[$a]." to the movie<br />\n";

function save_movie($file_name) {

function output_movie() {
header('Content-type: application/x-shockwave-flash');


// Simple button with link
 function makeRect($r, $g, $b){
   $s = new SWFShape();
   $s->setRightFill($s->addFill($r, $g, $b));
   return $s;
// Set Font
 $font = new SWFFont("test.fdb");
 $text1 = new SWFText();
 $text1->moveTo(155, 410);
 $text1->setColor(0x00, 0x00, 0x00);
 $b1 = new SWFButton();
 $b1->setUp(makeRect(0xff, 0, 0));
 $b1->setOver(makeRect(0xcc, 0, 0));
 $b1->setDown(makeRect(0, 0, 0xaa));
 $b1->setHit(makeRect(0, 0, 0));
 $b1->addAction(new SWFAction("getURL('', 'phpsite');"),
 $m = new SWFMovie();
 $m->setBackground(0xcc, 0xcc, 0xcc);
 $i = $m->add($b1);
header("Content-type: application/x-shockwave-flash");


If you are looking to do some simple interaction between Flash MX and php,
here is an extremely basic model to get you started. The Flash file has a simple
Input Text field which allows the user to enter text (ie a textbox). The flash
then passes the textfield to the php script for processing/database interaction etc.
The idea is a form made in Flash, but processing by php/mysql (or whatever). If you want
to handle all GUI in Flash, see the links below for more info.
All "Actions" or "Action Script" located in frame 1, layer 1.
In Flash, create an Input Box with an instance name of myTextBox.
Create a "submit button" using Insert>New Symbol>Movie Clip.
Dont use the PushButton Component or you will have to add
scripting to that component (ie outside Frame1 Layer1). Keeping all the
Action Script in Frame1 makes for a simpler example.
Next, click on the background in Frame1 (the "Properties" dialog
should show the Background color). Hit F9 to show actions for Frame1.
Enter the below code:
//Create object to hold vars
dataSender  = new LoadVars();
//Define submit button behavior
submit_button.onRelease = function() {
//assign properties to LoadVars object created previously
//myTextBox is instance name for input text box
//foo will be the var passed to php (ie $foo)
//Set foo to the text entered by user = myTextBox.text;
//Call flash's send function to send foo to the php script
//Using "_self" will pass control to the php script
dataSender.send("testFlash.php", "_self", "POST");
/* Put the swf file in an html file and upload it to the server
Create the below php file and save it as testFlash.php:
echo "foo= $foo";
Push testFlash.php to the same directory on the server and hit
your html file with your browser.
Parts of this code taken from:

Change Language

Follow Navioo On Twitter
.NET Functions
Apache-specific Functions
Alternative PHP Cache
Advanced PHP debugger
Array Functions
Aspell functions [deprecated]
BBCode Functions
BCMath Arbitrary Precision Mathematics Functions
PHP bytecode Compiler
Bzip2 Compression Functions
Calendar Functions
CCVS API Functions [deprecated]
Class/Object Functions
Classkit Functions
ClibPDF Functions [deprecated]
COM and .Net (Windows)
Crack Functions
Character Type Functions
Cybercash Payment Functions
Credit Mutuel CyberMUT functions
Cyrus IMAP administration Functions
Date and Time Functions
DB++ Functions
Database (dbm-style) Abstraction Layer Functions
dBase Functions
DBM Functions [deprecated]
dbx Functions
Direct IO Functions
Directory Functions
DOM Functions
DOM XML Functions
enchant Functions
Error Handling and Logging Functions
Exif Functions
Expect Functions
File Alteration Monitor Functions
Forms Data Format Functions
Fileinfo Functions
filePro Functions
Filesystem Functions
Filter Functions
Firebird/InterBase Functions
Firebird/Interbase Functions (PDO_FIREBIRD)
FriBiDi Functions
FrontBase Functions
FTP Functions
Function Handling Functions
GeoIP Functions
Gettext Functions
GMP Functions
gnupg Functions
Haru PDF Functions
hash Functions
Hyperwave Functions
Hyperwave API Functions
i18n Functions
IBM Functions (PDO_IBM)
iconv Functions
ID3 Functions
IIS Administration Functions
Image Functions
Imagick Image Library
Informix Functions
Informix Functions (PDO_INFORMIX)
Ingres II Functions
IRC Gateway Functions
PHP / Java Integration
JSON Functions
LDAP Functions
libxml Functions
Lotus Notes Functions
LZF Functions
Mail Functions
Mailparse Functions
Mathematical Functions
MaxDB PHP Extension
MCAL Functions
Mcrypt Encryption Functions
MCVE (Monetra) Payment Functions
Memcache Functions
Mhash Functions
Mimetype Functions
Ming functions for Flash
Miscellaneous Functions
mnoGoSearch Functions
Microsoft SQL Server Functions
Microsoft SQL Server and Sybase Functions (PDO_DBLIB)
Mohawk Software Session Handler Functions
mSQL Functions
Multibyte String Functions
muscat Functions
MySQL Functions
MySQL Functions (PDO_MYSQL)
MySQL Improved Extension
Ncurses Terminal Screen Control Functions
Network Functions
Newt Functions
NSAPI-specific Functions
Object Aggregation/Composition Functions
Object property and method call overloading
Oracle Functions
ODBC Functions (Unified)
ODBC and DB2 Functions (PDO_ODBC)
OpenAL Audio Bindings
OpenSSL Functions
Oracle Functions [deprecated]
Oracle Functions (PDO_OCI)
Output Control Functions
Ovrimos SQL Functions
Paradox File Access
Parsekit Functions
Process Control Functions
Regular Expression Functions (Perl-Compatible)
PDF Functions
PDO Functions
Phar archive stream and classes
PHP Options&Information
POSIX Functions
Regular Expression Functions (POSIX Extended)
PostgreSQL Functions
PostgreSQL Functions (PDO_PGSQL)
Printer Functions
Program Execution Functions
PostScript document creation
Pspell Functions
qtdom Functions
Rar Functions
GNU Readline
GNU Recode Functions
RPM Header Reading Functions
runkit Functions
SAM - Simple Asynchronous Messaging
Satellite CORBA client extension [deprecated]
SCA Functions
SDO Functions
SDO XML Data Access Service Functions
SDO Relational Data Access Service Functions
SESAM Database Functions
PostgreSQL Session Save Handler
Session Handling Functions
Shared Memory Functions
SimpleXML functions
SNMP Functions
SOAP Functions
Socket Functions
Standard PHP Library (SPL) Functions
SQLite Functions
SQLite Functions (PDO_SQLITE)
Secure Shell2 Functions
Statistics Functions
Stream Functions
String Functions
Subversion Functions
Shockwave Flash Functions
Swish Functions
Sybase Functions
TCP Wrappers Functions
Tidy Functions
Tokenizer Functions
Unicode Functions
URL Functions
Variable Handling Functions
Verisign Payflow Pro Functions
vpopmail Functions
W32api Functions
WDDX Functions
win32ps Functions
win32service Functions
xattr Functions
xdiff Functions
XML Parser Functions
XML-RPC Functions
XMLReader functions
XMLWriter Functions
XSL functions
XSLT Functions
YAZ Functions
YP/NIS Functions
Zip File Functions
Zlib Compression Functions
eXTReMe Tracker