Introduction to the Chat


A typical game chat allows you to perform the following actions:

  • Send and receive messages (duh!).

  • Send and receive private messages (ones that are sent to a specific user).

  • Join any room in the room list.

  • Create a room. The room is then added to the room list, and others can join it.

  • Challenge another user to a game.

  • Cancel a challenge you sent.

  • Accept or decline a challenge that has been sent to you.

The chat analyzed in this chapter lets you do all of those things and is the one we use with the multiplayer games in Part 3 of this book.

Let's first review this chat's technical situation: what it connects to, what form of information it sends, how you prepare the information, and so on.

graphics/hand_icon.gif

The chat application which consists of a single SWF file needs to connect with a socket server. A socket server is a software application that connects several people together to enable things like chats and multiplayer games. In this book we are going to use the ElectroServer socket server application, which was created for multiplayer games in Flash. In order for you to successfully run the chat file we'll describe in this chapter, you'll need to have ElectroServer up and running. So we will assume that you have installed it and know how to start it up. (To learn how to do this, see Appendix B.)

The main screen of the chat.

graphics/13fig01.gif

A big job already done for you

Flash talks to the socket server over an XML socket. This means that the messages sent and received are XML formatted. It's no easy task to build an application from scratch that understands which XML-formatted messages to send, and why and when to send them. Not only that, but the application would have to know how to interpret the incoming messages. That's why I created the ElectroServerAS object. This ActionScript object makes creating chats and multiplayer games in Flash a lot easier. With it you can easily do things like log in to the server or send a message by calling one simple method. You don't need to worry about formatting XML or remembering all of the complicated syntax the ElectroServerAS object does all that for you. It has more than 40 methods and properties. You can even install them into the Actions panel in Flash. The ElectroServerAS object is contained within the ElectroServerAS.as file found in the AppendixC directory on the CD. This object can be included in any Flash file by using the #include action.

graphics/arrow_icon.gif

All of the methods and properties contained in the ElectroServerAS object are defined in Appendix C,which also includes information on their installation and setup.


The ElectroServerAS object is a powerful piece of ActionScript that functions as the "command center" for running an online chat or multiplayer game managing, interpreting, sending, and delivering messages. It connects with the server, formats the messages appropriately, and informs you of the status of the connection and of the chat. But with the ElectroServerAS object, you can do many other things beyond these. Most of the additional functions apply directly to multiplayer games. For instance, in multiplayer games we can make use of server variables. A server variable is one that is stored by the socket server, and one that you can create from Flash. They are particularly useful for storing game information that everyone in the game can see, such as the card order in a shuffled deck.

With the ElectroServerAS object you can also send ActionScript objects between game players. For instance, one player can send an array of information that contains the position of a character. The other player then receives this array. You will see this done when we create multiplayer games in Part 3 of this book.



Macromedia Flash MX Game Design Demystified(c) The Official Guide to Creating Games with Flash
Macromedia Flash MX Game Design Demystified: The Official Guide to Creating Games with Flash -- First 1st Printing -- CD Included
ISBN: B003HP4RW2
EAN: N/A
Year: 2005
Pages: 163
Authors: Jobe Makar

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net