Use PHP to quickly generate Flash animation

Source: Internet
Author: User
RichInternetApplication is a new buzzword in Web2.0. in essence, a key component of Web2.0 is AdobeFlash. learn how to integrate Flash animation into applications and use the Ming library to dynamically generate Flash animation. In Web 2.0, Ri Rich Internet Application is a new buzzword in Web 2.0. in essence, a key component of Web is Adobe Flash. learn how to integrate Flash animation into applications and use the Ming library to dynamically generate Flash animation.

In Web 2.0, Rich Internet Application is introduced. but what does Rich Internet Application mean? Generally, it means adding highly responsive transaction operations to an application. Specifically, it means that widgets, Web forms, and reports on the page can be instantly changed without retrieving new pages from the server.

One method for building Rich Internet Application (RIA) is to use Dynamic HTML (Dynamic HTML, DHTML), which is Ajax, JavaScript, and Cascading Style Sheet (CSS) and HTML (see references ). However, DHTML is not the only way to add interactive operations to Web applications. Another important method is to use Adobe Flash Player, which has been used to add interactive operations for websites for ten years.

The first version of Flash was used to create animated images. The latest version of Flash can now host a complete interface for controlling Web service access and using ECMAScript (the official version of JavaScript) to provide complete script support.

Learn about Flash

Flash Player is integrated into running Microsoft? Windows? , Mac OS X, and Linux? A plug-in the Web browser of the computer. By the end of this article, the latest Flash Player version is V8. it is available for free and is installed with this plug-in most browsers. It is very popular and has excellent client penetration power-and this penetration power has been improved with the emergence of services such as YouTube and Google Video, which all use Flash to display Video streams.

Flash Player is only one end of the balance. To play a role, Flash Player also needs a Flash animation. This type of animation is usually a file compiled using a Flash development tool. its file extension is. swf. however, as you will see in this article, you can use the Ming library to dynamically build images in almost the same way as creating images dynamically. swf file, and draw images on the Web server. The Ming library uses PHP code to construct the operation code in the New. swf file.

You can use either of the two methods to view the. swf file on the Web site. In the first method, you only need to navigate to the URL of the. swf file. in this way, the entire content area of the Web server is replaced with the Flash animation. This method is easy to debug, but the main usage is to embed an animation into an HTML Web page.Marking. TheTag and then reference the SWF animation through the URL.The advantage of this method is that you can place an animation anywhere on the page and dynamically control it through JavaScript code, just like processing any other elements on the page.

Listing 1 shows a reference to SWF animation.Tag example.



Listing 1. Embedded Flash animation
                

This group of tags references an animation named lines.swf. InternalTags are used to ensure that Flash animation can be played in various browsers with plug-ins installed.

The Flash Player height and width are also specified as 550 pixels and 400 pixels respectively. It is worth noting that the graphics in Flash animation are based on vectors, which means that when you use Flash commands to draw lines and text, all elements are stored as coordinates and scaled according to the ratio of matching display areas. As you can see, Flash animation has its own coordinate system, you can follow the appropriate method to make the code as clean as possible.

Ming

The first method provided in this article to use Flash animation is to use the Ming library to dynamically generate them. The Ming library is a PHP library with a set of objects mapped to the data type in the SWF animation: subgraphics, graphics, text, bitmap, and so on. I will not discuss how to build and install Ming, because its operations are platform-specific and not very simple (see references ). In this article, I used the pre-compiled extension php_ming.dll library for PHP in Windows.

It must be noted that Ming is still in the development stage. As of the end of this article, the library version is V0.4, and some commands in earlier versions are not available in the latest version. I used V0.4 to write this article. Therefore, you need to use this version to use this code.

Listing 2 shows the HelloWorld example implemented using the Ming library.



Listing 2. Hello. php

    
            setFont( $f );$t->setColor( 0, 0, 0 );$t->setHeight( 400 );$t->addString( 'Hello World' );$m = new SWFMovie();$m->setDimension( 2500, 800 );$m->add( $t );$m->save( 'hello.swf' );?>            

Run this code in the command line to generate the hello.swf file. When I open the file in a Web browser, I see the result shown in Figure 1.



Figure 1. HelloWorld example using Ming

Looking back at this code, the first thing I do is to create a pointer pointing to a built-in font (_ sans), then create a text field, and set the font, color, and size, finally, it provides some text content ("Hello World "). Then createSWFMovieObject and set its size. Finally, add text elements to the animation and save the animation to the file.

As an alternative method for directly building files, you can also use the following code to make SWF animation output as a page without using the save method:

header( 'Content-type: application/x-shockwave-flash' );$m->output( );            

This process is similar to using the ImageMagick Library in PHP to build bitmap. For all the Ming examples, I will use the save method, but you can choose whether to use the save method based on your preferences.

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.