Sunday, January 23, 2022

Flash Tutorial for Web Developers: Create a Flash & PHP-Based Discussion Forum

While there are many discussion forum scripts available, often web developers are interested in creating their forum using Flash and the PHP scripting language. This tutorial will show you how to create your own Flash and PHP-based forum, and free source code is included!

Setting up your own discussion forum is actually fairly simple. There are only 3 parts to the forum that make everything work.

  1. Flash object
  2. Text document
  3. PHP File (with serverside PHP handler)

How to Create a Flash Object

[Note: You can download the complete source code for this example to try out with little to no changes needed for it to work. The .fla and .swf files are also included.]

First, start off with a few input boxes (make sure you change them to input type in the text properties). Than give those input boxes names. You will also need a dynamic text box for viewing the posts. Make sure that this text box is bigger and styled for multiline wordwrap, as the font will need to be viewed without scrolling over with the mouse.

Next you will need to make a submit button. I also included a reset button for my example. Put the following actions into the button:

on (release) {
if (name!=null & message!=null) {
getURL (“mssystem.php”, “_self”, “POST”);

Then in your first frame of the movie, use the following code to get the posts from your file:

loadVariablesNum (“mss.txt”, 0);
stop ();

Now you’ll create 2 scrolling buttons with the following actions:

on (release) {
return1.scroll = return1.scroll-1;

Note that you can change the other buttons actions to “+1” instead of “-” to make it scroll up instead of down.

  • Better understanding the submit actions – The reason for setting the values of the variables to null is to make sure that the .php file doesn’t see a variable to post when there isn’t one actually there.
  • Better understanding the first frame actions – The purpose of loading variables is to place the sent messages from the file back into Flash again.

Formating this text document is easy. Just put “&return1=” on the first line of the text document. Doing this will make Flash see it as a variable to replace when the Flash enters the first frame.

It is very important that you give this file a SPECIAL PERMISSION in your web hosting service. The file needs to have full write permissions or full write RECURSIVE permissions. This is required for the PHP script or the PHP file will not have the correct permissions needed to write new posts to this file.

The PHP Handler

Simply paste this code into a text document and name it mssystem.php.

<br><p align=left><embed src=mss.swf
height=285.3 width=688.8 wmode=”transparent”>
$name = $_POST[’name’];
$email = $_POST[’email’];
$message = $_POST[’message’];
if($name!=null & $message!=null){
$myFile = “mss.txt”;
$fh = fopen($myFile, ‘a’) or die(“can’t open file”);
$stringData = “——————————————–
————————————————n$name posted:
$message ncontact at: $emailn——————————–
fwrite($fh, $stringData);

As long as you have everything set up with the right permissions you will get no PHP errors and your posts will never disappear! Have fun!

Popular Articles