Creating A Multiplayer Game in Flash

Ready to start making the next social game? Well this tutorial will give you a starting point.

One of the hit things online is social gaming. I thought it would be fun and cool to get something going in the multiplayer area of gaming. In Flash Player 10.1, there was a feature called Cirrus was added, it’s a peer-to-peer feature that allows developers to create multiplayer games. Cirrus is free to use, you just need to go to the Adobe site and register to get the Developer key and server.

I ran across a source that had a list of open source codes libraries that have chat rooms, messaging, and etc. The resource is at the end of this posting. I tried a few of them, but couldn’t get any of them to work. I ran across one called Cocoon P2P. This one is open source and is really easy to implement. It doesn’t use Cirrus, but from what it looks like you can use it. For the purpose of this posting, I wanted to do something quick, but gets the point across.

Using Cocoon, I created a really small Flash application that counts the number of users. I know, I should’ve done something wicked cool, like a small game or something. In under 26 lines of code, I achieved what I wanted to do. I am excited I got it to work. I hope to explore this more and implement it in a game or application in the near future.

Here is a snippet of my code:
import com.projectcocoon.p2p.LocalNetworkDiscovery;

var channel = new LocalNetworkDiscovery();
var users:Number =0;

channel.addEventListener(ClientEvent.CLIENT_ADDED, onClientAdded);

function onClientAdded(event:ClientEvent):void{
numUsersTextField.text = String(users);


I was not paid to endorse any products or services that were mentioned in this post.