Функції Ming


add a note add a note

User Contributed Notes 10 notes

dank at nospam dot org
17 years ago
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
    dataSender.foo = 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:
kunnoichi at hotmail dot com
21 years ago
//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');
rolf at winmutt dot com
15 years ago
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="/creativesyndrome.com/logo.png"><br><a href="?l='.$l.'&o='.($o+$l).'">next ></a>';exit;

pundek at gmail dot com
5 years ago
For better resolution in browser, change ming name to chow asian
Scottie_Too_Hottie7 at lycos dot com
17 years ago
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!

catfarm at gmail dot com
15 years ago
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.


= 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.
random at nowhere dot com
15 years ago
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])."<br>";
$s=unpack("V",substr($d,4,4)); echo "FileSize : ".$s[1]." bytes<br>";

// 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)."<br>";
echo "height=".(($ymax-$ymin)/20)."<br>";
wokan at cox dot net
18 years ago
For those who don't get the naming, _Ming_ the Merciless was comic book hero _Flash_ Gordon's arch enemy.
gaz_b3 at yahoo dot com
19 years ago
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:

ivv_rousse at yahoo dot com
21 years ago
// Simple button with link


makeRect($r, $g, $b){
$s = new SWFShape();
$s->setRightFill($s->addFill($r, $g, $b));

// 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('http://www.php.net/', 'phpsite');"),

$m = new SWFMovie();
$m->setBackground(0xcc, 0xcc, 0xcc);

$i = $m->add($b1);

header("Content-type: application/x-shockwave-flash");
To Top