使用PHP 快速生成Flash 动画_PHP
Rich Internet Application 是 Web 2.0 中的新时髦词,并且就 Web 2.0 的实质而言,一个关键组件就是 Adobe Flash.了解如何将 Flash 动画集成到应用程序中,并使用 Ming 库动态生成 Flash 动画。
Web 2.0 引入了 Rich Internet Application.但 Rich Internet Application 的含义是什么?通常,它意味着向应用程序中添加具有高度响应能力的交易操作。具体来说,它意味着可以即时更改页面中的小部件、Web 表单和报告,而无需从服务器中检索新页面。
一种用于构建 Rich Internet Application(RIA)的方法就是使用动态 HTML(Dynamic HTML,DHTML),它是 Ajax、JavaScript、层叠样式表(Cascading Style Sheet,CSS)和 HTML 的组合(请参阅 参考资料)。但是 DHTML 并不是向 Web 应用程序中添加互动操作的惟一方法。另一种重要方法是使用 Adobe Flash Player,使用它为 Web 站点添加交互操作已经有十年的历史。
第一版的 Flash 曾是用于创建动画图片的工具,而最新版本的 Flash 已经可以托管一个完整的界面,可用于控制 Web 服务访问并使用 ECMAScript(JavaScript 的正式版本)来提供完整的脚本支持。
了解 Flash
Flash Player 是集成到运行 Microsoft? Windows?、Mac OS X 和 Linux? 的计算机的 Web 浏览器中的一个插件。截至本文完稿时,最新版本的 Flash Player 是 V8.它是可以免费获得的,大多数浏览器都附带安装了此插件。它十分流行并且具有优秀的客户机渗透力 —— 而这种渗透力随着 YouTube 和 Google Video 这类服务的出现得到了提高,这些服务都使用 Flash 显示视频流。
Flash Player 只是天平的一端。要发挥作用,Flash Player 还需要使用一个 Flash 动画。此类动画通常是使用一种 Flash 的开发工具编译的文件,其文件扩展名为 .swf.但正如您将在本文中看到的那样,还可以使用 Ming 库用几乎与动态创建图片相同的方法来动态构建 .swf 文件,并在 Web 服务器上绘制图形。Ming 库利用由 PHP 代码构建的对象和方法在新的 .swf 文件中构建操作代码。
您可以通过两种方法中的任意一种方法来查看 Web 站点中的 .swf 文件。第一种方法只需导航到 .swf 文件的 URL.这样做将把 Web 服务器的整个内容区域替换为 Flash 动画。此方法便于进行调试,但主要的用法还是将动画嵌入到 HTML Web 页面的
清单 1 显示的是一个引用 SWF 动画的 <font face="新宋体"><object></object></font>
标记的示例。
清单 1. 嵌入式 Flash 动画
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab# version=6,0,40,0" WIDTH="550" HEIGHT="400"> <PARAM NAME="movie" VALUE="lines.swf"> <EMBED src="lines.swf" WIDTH="550" HEIGHT="400" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"> </EMBED> </OBJECT> Copy after login |
这组标记将引用一个名为 lines.swf 的动画。内部的 <FONT face=新宋体><embed></FONT>
标记用于确保 Flash 动画可以在安装了插件的各种浏览器中播放。
标记还把 Flash Player 的高度和宽度分别指定为 550 像素和 400 像素。非常值得注意的是,Flash 动画中的图形都是基于矢量的,这意味着当您使用 Flash 命令绘制线条和文本时,那些元素都被存储为坐标并且按照匹配显示区域的比例进行缩放。如您所见,Flash 动画有自己的坐标系统,您可以按照适合自己的方法使代码尽可能整洁。
Ming
本文中提供的使用 Flash 动画的第一种方法是使用 Ming 库动态生成它们。Ming 库是一个 PHP 库,其中有一组映射到 SWF 动画中的数据类型的对象:子图形、图形、文本、位图等等。我将不讨论如何构建和安装 Ming,因为其操作是特定于平台的而且并不特别简单(请参阅 参考资料)。在本文中,我使用了预编译的扩展 php_ming.dll 库用于 Windows 版本的 PHP.
必须指出的是,Ming 仍处于开发阶段。截至本文完稿时,库的版本是 V0.4,并且较老版本中的一些命令在最新版本中不能使用。我使用了 V0.4 撰写本文,因此,要使用这段代码,您需要使用这个版本。
清单 2 显示了使用 Ming 库实现的 HelloWorld 示例。
清单 2. Hello.php
<?php $f = new SWFFont( '_sans' ); $t = new SWFTextField(); $t->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' ); ?> Copy after login |
在命令行中运行这段代码将生成文件 hello.swf。当我在 Web 浏览器中打开该文件时,看到了图 1 所示的结果。
图 1. 使用 Ming 的 HelloWorld 示例
回过头来查看这段代码,我做的第一件事是创建指向一个内置字体(_sans)的指针,然后创建文本字段,设定字体、颜色和大小,最后为其提供一些文本内容(“Hello World”)。再接下来创建了一个 <FONT face=新宋体>SWFMovie</FONT>
对象并设定其尺寸。最后,向动画中添加了文本元素并将动画保存到文件中。
作为直接构建文件的替代性方法,也可以使用下面的代码,使 SWF 动画像页面那样输出,而无需使用 save 方法:
header( 'Content-type: application/x-shockwave-flash' ); $m->output( ); Copy after login |
此过程类似于使用 PHP 中的 ImageMagick 库来构建位图。对于所有 Ming 示例,我都将使用 save 方法,但您可以根据喜好来选择是否使用 save 方法。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension
