PHP 5 Sockets with Flash 8
       by obiAdmin (raymond): 30 September 2006

Ever wanted to build a real-time chat room or build a high speed multiplayer game but couldn't figure out how to do that? Sockets are what your missing! PHP sockets are indeed very nice to use when creating real-time chat applications or to build an instantaneous multiplayer game. Unfortunately most people do not use them because they are hard to grasp. In this tutorial, I will be showing how to write a simple PHP5 socket shell script for Apache servers, and how to set up a Flash file to connect to it.

Here is a snap shot of the chat room you'll be creating in this tutorial:

[ an example of the chat program you will create ]

This tutorial has many parts to it, to help you navigate and understand what it is I am trying to explain it has been expanded to many pages. This tutorial does have a lot of information to cover even for a simple application like what you will create. Here are some things I will be covering in my tutorial:

  1. Building the Flash client to connect to the PHP5 socket.

  2. Script the PHP5 socket.

  3. Write a Batch file to run the PHP5 socket through command prompt.

  4. Other steps to making this chat more advanced.

Before we begin, I am assuming you have Apache2.x installed along with PHP5 and Flash 8. To install Apache2.x and PHP5, go here.

Lets Get Started
Let us begin with the client side. Go ahead and create a new html file called flash.html. We will place the flash chat room in there. With that done, let's get into creating the Flash document.

Start a new Flash document and make the width '550 px' and height '400 px'. Create a new layer and name it actions. Lock your newly created actions layer, for it will serve for just coding only.

Place a Dynamic Text box onto the stage of your other layer and give it an instance name of "msgArea". Also check to make sure your dynamic text box has the HTML box selected:

[ make sure your properties looks like mine]

Now place an Input Text box right below your msgArea box and give it an Instance name of "inputMsg":

[ notice the multi-line text in case people want to type a lot! ]

So right now, we are still missing some things, go ahead and drop a UI scrollbar on to your msgArea so the content inside may be scrolled. You can find these by going to Window tab, and clicking on Components. The UI Scrollbar will automatically resize to the height of your msgArea. Also, drag and drop a Button component into the stage. Your Flash stage should look something like this right now:

You need to give the newly added button an Instance Name of "pushMsg". Once you have done that, you can then select the parameters tab located by the properties tab and change the label to "Send":

Alright, so now we need to start adding some ActionScript to this mighty beast! In the next page I will show you the ActionScript and explain what it will do.


1 | 2 | 3 | 4 | 5 | 6

SUPPORTERS:'s fast and reliable hosting provided by Media Temple.