Using PHPObject to Save and Retrieve Simple Game Levels
[ May 27, 2004 ] by Tor de Vries
Using a simple video game level editor in Flash as a foundation, this whitepaper/tutorial explains how to use ActionScript, PHP, and the PHPObject "Flash remoting" libraries to save and retrieve data to/from a server in XML format.

What You Need

The Flash file is "leditor.fla", and the PHP class file is "Leditor.php", both available in this downloadable archive (, 168k). The Flash file requires Flash MX 2004, and uses some components from Flash MX 2004 Pro.

To install PHPObject, you need to install the free Macromedia Extensions Manager.

You also need Ghostwire's free PHPObject Flash remoting libraries. As of this writing, the latest version is v1.45. Newer versions may or may not work the same. Once you have downloaded and expanded the PHPObject ZIP archive, double-click on the file "PHPObject.mxp". This will launch the Extensions Manager and walk you through the process of installing the relevant Flash libraries

You also need a web browser with a recent copy of the Flash plug-in. Mac users, note that versions of Apple's Safari browser prior to 1.2 do not work correctly with Flash remoting, although Internet Explorer 5 and Netscape 7 work fine.

To test out the sample level editor, you also need a web server that has PHP4. The examples in this document use a Mac OS X system, with the computer itself as the web server ("localhost"). However, any web-accessible server should work. You will need to be able to put files in a directory (via ftp) and access them from a web browser (via http://). Create a directory on your web server (such as "leditor"). (Depending on how your server is configured, you may need to change the file permissions of your directory to allow everyone to write to it. Most FTP and SFTP programs offer simple ways of setting these permissions.)

Finally, open up the "leditor.fla" file in Flash MX 2004. Click on the first frame of the first layer and look at the ActionScript in that frame. Near the top, you will see this line:

_global.defaultGatewayDir = "http://localhost/leditor/";

The second half of this line is the web URL to the directory you created on the server. If this is not running on your local computer ("localhost"), then change it to the actual URL of the directory you just created (such as ""). Then, go into Flash's "Publish Settings" and make sure it is set to create Flash Player 6 movies (not Flash Player 7!) and publish the movie to the file "leditor.swf".

Setting Up the Game Editor

To run the level editor, copy the following files into the directory you created on your web server:

» leditor.swf which you just published from Flash, above.

» index.html from the leditor download.

» Sample_Level.xml from the leditor download.

» Leditor.php from the leditor download.

» Gateway.php from the PHPObject download (in its "server" folder).

» config.php from the PHPObject download (in its "server" folder).

To test it, pull up your leditor directory in your web browser. You should see something like this:

If you've gotten this far, great! You can open the sample level, or use the level objects to draw your own level and save it to the server.

Name: Tor de Vries
Location: New York
Age: 30
Flash experience: I first began toying with it back when it was called "FutureSplash" and wasn't owned by Macromedia, if anyone else remembers that. Since then it has been a favorite tool alongside DHTML, JavaScript, PHP, Perl, XML and other buzzwords.
Job: Digital Designer
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| | | |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048