Resources

Foundation PHP 5 for Flash by David Powers

An excellent resource with easy to follow tutorials and examples that make sense. Source code files include various stages of each project allowing you to check as you go.

Advanced PHP 5 for Flash by Steve Webster, Matt Rice, Kev Sutherland, Jacob Hanson, James Palmer, Todd Marks, Havard Eide, Håvard Eide

Includes sections on Flash Shared Objects, Sessions, File Uploading, Advanced MySQL, Sockets and XML.

HTML URL-encoding Reference w3schools.com

A good reference for ASCII characters in URL-encoding form.

Flash MX and PHP actionscript-toolbox.com

A tutorial for building a dynamic address book with Flash and PHP. The section on LoadVars is especially good.

Using ext/mysqli: Part I - Overview and Prepared Statements by Zak Greant and Georg Richter

Discussion of the mysqli extension for PHP5.

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.
  • 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:

  • 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.

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.