Create Flash animations dynamically with PHP

Source: Internet
Author: User
Tags define copy ming php and
Create a dynamic Macromedia Company's Flash Animation software has become a very popular performance tool on the Web page, Web developers use it to arouse the interest of viewers. Unfortunately, only using ActionScript to create animations is very limited, and Macromedia has announced plans to abandon the flash generator product and instead adopt cold Fusion, which supports Flash MX, where will our site go? Now, we can use the Ming PHP library to easily create Flash animations dynamically 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, tightly integrated with PHP, but the library is still in the experimental phase, the current version is 0.2a, online tutorials, examples, and help manuals can make it easy to learn, and the functions of Ming are organized and convenient for PHP and flash developers to find. The use of PHP and the Ming Library not only allows our site to have gorgeous decoration, but also reduce the cost of developing flash animation and complex labor.
There are two ways to use the Ming Library, we can embed it in PHP (for UNIX platforms), or we can run it as a PHP module, where functions support all platforms and need not be instantiated when used. If we were to run the Ming Library as a PHP module, we would have to explicitly call the Ming Library and use other modules, and then use the functions in that library. Because the module must be loaded before use, there is a drop in performance compared to how the Ming is compiled as an internal function.
The Ming Library is completely free, we can download to the creator's website, the address is: http://www.opaque.net/ming/, the website ... php.net/ming.
Once we have properly installed and configured the Ming Library, we can create a PHP object that invokes the functions of the Ming from PHP, and by calling functions and properties, we can define our animations. There are 13 objects in the PHP module that provide some of the features of Flash, and several commands to control the release parameters. Let's see how you can use it to create animations.
To create a SWF-formatted animation using Macromedia Flash, we first create some symbols that Flash has three types of symbols: graphics, animated clips, buttons. Once we have created these symbols, we can copy them into the scene, each copy being called an instance, and we can put any number of instances into our scene. You can then define the behavior of these objects, that is, define motion and motion trajectories, or define animation parameters, 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 have to create symbols that are examples of PHP objects, and then define the positions and interrelationships of the objects in the animation scene, and then define the actions of the objects in each frame. Finally define the animation yourself. We can directly output SWF directly to the browser, can also be saved in SWF format files for later use. The advantage of Flash is the graphical user interface, the use of the Ming library can not only be 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:

<?php

/* Create a symbol First and fill 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 the animated clip and add some scripts.
$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 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 ("settarget ('/box ')" (new swfaction); gotoAndPlay (2); "), Swfbutton_mousedown);

/* Create the 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 ();
?>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.