Macromedia Company's Flash (Flash training) animation software has become a very popular web page Performance tool, Web site developers use it to arouse the interest of the visitors. Unfortunately, however, there is a big limit to creating animations using ActionScript, and Macromedia has announced that it intends to abandon the flash generator product and switch to cold Fusion, which supports Flash MX, where will our website go? Now we can easily dynamically create flash animations using the Ming php (PHP tutorial) library, and seamlessly integrate with our code. We can create animations of various effects based on the data in the database.
The Ming animation library originally appeared in the PHP4.05 version, replacing the previous version of the libswf module. The Ming library is written in C and supports multiple languages, so let's take a look at how to make animations using PHP. The library is simple to use and tightly integrated with PHP, however, the library is still in the experimental phase, the current version is 0.2a, online tutorials, examples, and help manuals can be easily learned, Ming functions organized in a very organized way, convenient for PHP and flash developers to find. Using PHP and the Ming Library not only gives our website a gorgeous decoration, but also reduces the cost of developing flash animations and complicated labor.
There are two ways to use the Ming library, which we can embed in PHP (for UNIX platforms), or as a PHP module that supports all platforms and does not need to be instantiated when used. If we were to run the Ming Library as a PHP module, we had to explicitly call the Ming library, just like the other modules, and then use the functions in that library. Since the module must be loaded before use, there is a bit of performance degradation compared to the way Ming is compiled as an internal function.
Ming Library is completely free, we can download to the creator's website, the address is: http://www.opaque.net/ming/, the site has a detailed user manual and Help, before use, please look at the installation and configuration instructions, address is:/http Www.opaque.net/ming/install.html. In addition, on the PHP website also has the user manual and the detailed explanation, the address is: http://www.php.net/ming.
Once we have properly installed and configured the Ming Library, we can create a PHP object, call the Ming function from PHP, and define our animations by invoking functions and properties. There are 13 objects in the PHP module that provide some of the features of Flash, as well as several commands to control the parameter setting at the time of release. Here's a look at how to use it to create animations.
Using Macromedia Flash to create the SWF format animation, we first create some symbols, Flash has three types of symbols: graphics, animation clips, buttons. Once we have created these symbols, we can copy them into the scene, each of which is called an instance, and can put any number of instances into our scene. You can then define the behavior of these objects, that is, define the motion and motion trajectory, or you can define the parameters of the animation, such as size and background color, which can be saved if needed. SWF file.
Using PHP's Ming library to create Flash animations, like Macromedia Flash, you must first create some symbols that are examples of PHP objects, then define the positions and interrelationships of those objects in the animated scene, and then define the actions of the objects in each frame, Finally define the animation itself. We can directly export the SWF directly to the browser, or we can save it in SWF format for future use. The advantage of Flash is the graphical user interface, the use of Ming Library can not only more simple control objects, but also has unlimited scalability and reuse.
Let's take a complete example to see how to use the Ming library:
/* First create a symbol and fill in the color */
$square = new Swfshape ();
$sqfill = $square->addfill (0, 0, 0xff);
$square->setrightfill ($sqfill);
$square->movepento ( -250,-250);
$square->drawlineto (250,-250);
$square->drawlineto (250,250);
$square->drawlineto (-250,250);
$square->drawlineto ( -250,-250);
/* Use the above symbol in an animated clip and add some script */
$sqclip = new Swfsprite ();
$i = $sqclip->add ($square);
$i->setdepth (1);
$sqclip->setframes (25);
$sqclip->add (New Swfaction ("Stop ();"));
$sqclip->nextframe ();
$sqclip->add (New Swfaction ("Play ();"));
for ($n =0; $n <24; $n + +) {
$i->rotate (-15);
$sqclip->nextframe ();
}
/* Create a button below */
function rect ($r, $g, $b) {
$s = new swfshape ();
$s->setrightfill ($s->addfill ($r, $g, $b));
$s->drawline (500,0);
$s->drawline (0,500);
$s->drawline ( -500,0);
$s->drawline (0,-500);
return $s;
}
$b = new Swfbutton ();
$b->addshape (Rect (0xff, 0, 0), SWFBUTTON_UP | Swfbutton_hit);
$b->addshape (Rect (0, 0xFF, 0), swfbutton_over);
$b->addshape (rect (0, 0, 0xff), Swfbutton_down);
$b->addaction (New Swfaction ("Settarget ('/box '); gotoAndPlay (2); "), Swfbutton_mousedown);
/* Create an animation below and add the symbols and buttons above */
$m = new Swfmovie ();
$m->setdimension (4000,3000);
$i = $m->add ($sqclip);
$i->setdepth (3);
$i->moveto (1650, 400);
$i->setname ("box");
$i = $m->add ($b);
$i->setdepth (2);
$i->moveto (1400,900);
/* Finally, we output it to the browser */
Header (' Content-type:application/x-shockwave-flash ');
$m->output ();
?>
Well, run it on your machine and see if it's the same as creating it with flash! For more function descriptions, refer to the operating manual.
Dynamically create Flash animations with PHP