Why PHP?
Although Flash is, in many ways, a self-contained environment, that doesn’t mean it can do everything. There are some things that PHP can do that ActionScript can’t, and other things, that although both languages can do, PHP does them more efficiently. For example:
- Flash can’t generate an (X)HTML page that has all of your carefully thought out header items.
- Flash can’t do server-side scripting. Although Flash is a self-contained environment, it only exists client-side. Anything you might want to add to your movie that includes server-side scripting such as a call to a database, an RSS feed, server-side validation, storing session variables, etc., requires a language capable of doing server-side scripting, such as PHP.
- Although some types of form validation can be done by ActionScript, PHP does it much more efficiently. Of course, the downside is that PHP requires a round trip to the server. A good solution is to do a preliminary validation with ActionScript to catch the gross errors and then have PHP execute a more finely-tuned validation.
Have you ever created a Flash movie that needs to include some code outside of the actual movie? For example, you might have used a JavaScript function or two – perhaps the window.open() method to create some popup windows within the movie or maybe a couple of functions to validate a form. Although you place the call to the functions within the Action Script, the functions themselves need to be included in the head of the (X)HTML document, which Flash doesn’t know how to do.
“Easy,” you say. Just create the header exactly like you want it, and plop the necessary portion of the Flash generated (X)HTML script into the <body> tag right before you upload to the Web. Sure. A perfect solution. But since we’re going to go to that much trouble anyway, why not create a template engine with PHP so we can also include some neat server-side stuff, like the ability to use include files for repeated page elements, to dynamically update content or to automatically generate a new date for our copyright notice each year? This segues nicely to:
Sound enticing? The remainder of this article will give you an overview of the tools you’ll need to implement these and other neat things.