Use PHP to dynamically create Flash animation

Source: Internet
Author: User
Tags php website
Flash animation software developed by Macromedia has become a very popular performance tool on web pages. website developers use it to attract the interest of viewers. However, unfortunately, it is very limited to create an animation using only ActionScript. Macromedia has announced its intention to abandon the FlashGenerator product, in turn, Flash animation software from ColdFusion Macromedia, which supports Flash MX, has become a very popular performance tool on web pages. website developers use it to attract viewers. However, unfortunately, it is very limited to create an animation using only ActionScript. Macromedia has announced its intention to abandon the Flash Generator product and switch to Cold Fusion that supports Flash MX, where will our website go? Now, we can use the Ming PHP library to easily and dynamically create Flash animations and integrate them seamlessly with our code. We can create various animations with different effects based on the data in the database.
Ming animation library first appeared in PHP4.05, replacing the LibSwf module of previous versions. The Ming library is written in C and supports multiple languages. let's take a look at how to use PHP to make animations. This library is simple to use and closely integrated with PHP. However, this library is still in the experimental stage. The current version is 0.2a, online tutorials, examples, and help manuals allow us to learn more conveniently. Functions in Ming are organized to facilitate search by PHP and Flash developers. Using the PHP and Ming libraries not only gives our website a gorgeous decoration, but also reduces the cost and complexity of developing Flash animations.
There are two methods to use the Ming library. we can embed it into PHP (for Unix platforms) or run it as a PHP module. the functions in the library support all platforms, it does not need to be instantiated during use. If we run the Ming library as a PHP module, we must call the Ming library explicitly, just like using other modules, and then use the functions in the library. Since modules must be loaded before use, there is a slight reduction in performance compared to using Ming as an internal function compilation method.
The Ming library is completely free. we can download it from the creator's website. In addition, the PHP website also provides user manual and detailed instructions at: http://www.php.net/ming.
Once we have correctly installed and configured the Ming library, we can create a PHP object, call the Ming function from PHP, and define our animation by calling functions and attributes. There are 13 objects in the PHP module, which provide some Flash functions, and several commands can be used to control the parameter settings during release. The following describes how to use it to create an animation.
Using Macromedia Flash to create an animation in SWF format, we first create some symbols. Flash has three types of symbols: graphics, animation editing, and buttons. Once we have created these symbols, we can copy them to the scenario. Each copy is called an instance, and we can let many instances into our scenario. Next, you can define the behavior of these objects, that is, define the action and motion track, or define animation parameters, such as the size and background color. if necessary, you can save them. SWF file.
Use the PHP Ming library to create Flash animation. like Macromedia Flash, you must first create some symbols, which are examples of PHP Objects, then define the positions and relationships of these objects in the animation scenario, define the actions of the objects in each frame, and finally define the animation itself. We can directly output SWF to the browser, or save it as a SWF file for future use. Flash has the advantage of graphical user interfaces. Using the Ming library can not only control objects more easily, but also have unlimited scalability and reuse.
Next we will use a complete example to see how to use the Ming library:


/* Create a symbol 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-> FIG (-250,250 );
$ Square-> drawLineTo (-250,-250 );

/* Use the above symbol in the animation 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 (, 0 );
$ S-> drawLine (0,500 );
$ S-> drawLine (-500,0 );
$ S-> FIG (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 and add the above symbol and Button */

$ M = new SWFMovie ();
$ M-> setDimension );

$ I = $ m-> add ($ sqclip );
$ I-> setDepth (3 );
$ I-& gt; moveTo (1650,400 );
$ I-> setName ("box ");

$ I = $ m-> add ($ B );
$ I-> setDepth (2 );
$ I-& gt; moveTo (1400,900 );

/* Finally, we output it to the browser */

Header ('content-type: application/x-shockwave-Flash ');
$ M-> output ();
?>

Okay, run it on your machine to see if it is the same as it was created with Flash! For more information about functions, see The Operation Manual.

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.